Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XBee 3 Cellular LTE-M/NB-IoT - memory leak #47

Open
kmm1001001 opened this issue Jul 10, 2020 · 3 comments
Open

XBee 3 Cellular LTE-M/NB-IoT - memory leak #47

kmm1001001 opened this issue Jul 10, 2020 · 3 comments

Comments

@kmm1001001
Copy link

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

@kmm1001001
Copy link
Author

Sorry, I forgot to attach the test data.
Digi_memory_testing.xlsx

Thanks,
Kris

@mikewadsten
Copy link
Contributor

mikewadsten commented Jul 10, 2020

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.)

@kmm1001001
Copy link
Author

Latest update:

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.

Thanks,
Kris

main_py.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants