You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am running a small micropython code loop on XBee 3 Cellular LTE-M/NB-IoT hardware, firmware version 11415. Using examples from the digi documentation and GitHub I simply instantiate a XBee and a network object, test network connection, calculate my next wake up time and then force sleep. Things are running fine except that before I sleep I look at my free and allocated memory. Then I run garbage collection and then look at the memory again. I'm noticing a small memory leak. Its not every time through the loop but over time it adds up. My solution as of now is to set a threshold level and safely shutdown the cell module and reboot. Just wondering if anyone can help debug where I am going astray. Attached is a txt file of my code.
The MicroPython garbage collector is very conservative, so a small "memory leak" while in an execution loop isn't really concerning, as long as the GC is able to collect that memory later.
Do note that all the calls to e.g. print(gc.mem_alloc()) will, themselves, trigger a memory allocation.
Have you tried testing what happens if you replace the sleeping logic (everything from '''<30s just wait; >10m something wrong''' down) with something like time.sleep_ms(50)? That way you can see if the GC truly is failing to collect the extra memory. (You know this is the case if you hit a MemoryError.)
I have attached my latest code, which is a bit cleaner. As you suggested, I replaced the x.sleep_now(x, False) with just a time.sleep_ms(x). Where x = 120000. This seems to work without leaking a single byte. If I only swap out the time.sleep_ms(x) with the x.sleep_now(x, False) I once again start dropping bytes every few times through the loop.
Hello,
I am running a small micropython code loop on XBee 3 Cellular LTE-M/NB-IoT hardware, firmware version 11415. Using examples from the digi documentation and GitHub I simply instantiate a XBee and a network object, test network connection, calculate my next wake up time and then force sleep. Things are running fine except that before I sleep I look at my free and allocated memory. Then I run garbage collection and then look at the memory again. I'm noticing a small memory leak. Its not every time through the loop but over time it adds up. My solution as of now is to set a threshold level and safely shutdown the cell module and reboot. Just wondering if anyone can help debug where I am going astray. Attached is a txt file of my code.
main_py.txt
Thanks,
Kris
The text was updated successfully, but these errors were encountered: