-
Notifications
You must be signed in to change notification settings - Fork 6
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
Out of memory errors on use of Screen.REPLACE for rotating screens #13
Comments
After absolutely extensive testing, I've isolated the issue to the button |
That is an interesting observation; I'm keen to fix this as Does this occur with any |
I've pushed an update to If a button had Please report any observations. |
Thank you for the quick response and patch! I've done some further experimentation today and come to the conclusion that the latest patch has mostly fixed the issue. When just pressing a button which would switch screens, it seems to reclaim memory sufficiently, however if another button with That being said, this is still a radical improvement as I believe the latter situation is a lot more rare and I can't readily think of an instance where that would be the desired way of inputting to the device - rather it seems more a side effect of sloppy input. Thanks again for your help! |
Thank you for the feedback. I'll give this some more thought. |
After further thought, I haven't figure out a way this can happen with synchronous code. However it can happen with asynchronous code. Assume two buttons, both operating on release. One changes screen, the other launches a task which lights an On one scan of the screen's widgets, the two release callbacks run. The order in which they run is indeterminate, so the task may be instantiated before the screen changes. The screen change is synchronous, but by then the task is running. The task retains a reference to the The quick fix is to register the task with Please let me know if your callbacks run such code. |
I'm attempting to cycle between screen instances using a similar methodology to screen_replace.py, but I'm finding that after enough cycles, my program crashes yielding
MemoryError: memory allocation failed, allocating 376 bytes
(it is consistently 376 bytes)
The screens themselves are somewhat complex, consisting of about 44 widgets, however I am using the Screen.REPLACE method, which if I understand the documentation correctly is supposed to essentially mark the prior screens for clearing by the garbage collector. I do pass a callback and two small strings through to each subsequent screen instance, however the demo in screen_replace.py appears to pass some data forward similarly as well.
In my efforts to debug this, I've made use of the micropython mem_info readout prior to and after executing the screen change to ascertain memory usages. As expected, changing the screen takes considerable memory, however it appears that the majority of that memory gets re-freed prior to next button press. Some memory is not freed, however; it seems like at least 13000 bytes get taken out of free memory with each press. Presses were done with several second intervals to try to differentiate from retained memory vs memory the garbage collector had not freed yet.
After observing this, I also introduced a manual gc.collect() call on the initialization of the screen just to be sure it isn't an issue with the garbage collector not freeing the previous screen in time, but that appears to have little if any impact.
I've also tried restarting execution (stopping the program with the close button and then starting it again from the computer) and found that the memory still wasn't freed.
I would adopt some of the suggested methods of reducing library memory usage, but it seems more from the diagnostics that this is some kind of memory leak, which would render those options ineffective anyways.
Any have any suggestions, clarifications, recommendations, or further information that might allow me to resolve this issue would be greatly appreciated!
The text was updated successfully, but these errors were encountered: