Replies: 1 comment 3 replies
-
It might be best to take this up with the author. Evidently you have plenty of free RAM - 138560bytes - but something in the code is attempting to allocate 8193 bytes. You are probably suffering from memory fragmentation. You could prove this (rather than the memory leak hypothesis) by having your exception handler do gc.collect()
print(gc.mem_free()) # I'll bet you still have plenty You can't defragment RAM. I would try to find out what is allocating such a large buffer and check whether it can be pre-allocated. It is wise to allocate any large buffers at the program start, before fragmentation can take hold. Then re-use the existing buffers as needed. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Howdy, thanks for micropython -- its great! I am the author of a deployable routine for automating indoor plant growing https://github.com/opensensor/growmax and I have run into an issue with the pico w and the Framebuffer which is trying to allocate memory when I call .text() and failing after some iterations of the routine. I don't have this issue on a similar sized 2-bit grayscale display, so part of it may be the extra contiguous memory required. I can run the same code fine on an ESP32S3 so I don't believe there is a memory leak or it would eventually run into the same issue -- also I invoke the garbage collector consistently throughout the routine and it is reporting back most of the memory is free before I invoke the framebuffer.text calls, which apparently each one re-allocates the buffer? I am confused on this point as well: I passed in an initially allocated buffer and never assumed it was getting reallocated, but I imagine its possible for reasons. Still I am confused how it could be failing to allocate memory.
Currently running v1.19.1-966-g05bb26010 on 2023-03-13 and also tried 04-11 with the same issue. I get a different issue with the I2C not being able to initialize properly at all on the latest stable 1.20 release and latest nightly builds unless I use SoftI2C which I don't want to do.
Local to Thonny I've tried many refactors without success (removing all print() statements, refactoring the SSD1327 display class down to be a subclass of framebuffer so it was even lighter weight, removing the Timer class I recently added for motion sensors and just had the display on the entire time, and within 1-4 iterations the display freezes, Thonny sees that memory allocation failed, and the rest of the routine continues to function albeit with a frozen display. Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions