I was reviewing the following code...
Code: Select all
import gc
import usocket as socket
import ustruct as struct
gc.collect()
from ubinascii import hexlify
import uasyncio as asyncio
gc.collect()
from utime import ticks_ms, ticks_diff
from uerrno import EINPROGRESS, ETIMEDOUT
gc.collect()
from micropython import const
from machine import unique_id
import network
gc.collect()
from sys import platform
Initially this stuck me as a bit odd, given that modern heap management should optimize and deference heap pointers, but above code suggests that gc is not that flexible or otherwise limited. Is that really the case? Would not setting a gc threshold service as a method to encourage gc to do the work, versus calling it explicitly over and over as above? Or is it the case that the loading the various modules severely (can) fragment the heap, and gc can't handle it without explicit invocation? Just looking for a bit of confirmation or clarity on why the above was done, as it was done.