memory problems #14294
Replies: 4 comments 1 reply
-
By my count your line 30 memory occurs at im=import(f"/exports/output_frames{i}"). The only way I've been able to get around running out of memory is to declare a byte array early in the program to reserve space before memory gets fragmented then put stuff into that rather than a variable. It's a PITA because byte array lacks some of the functionality of variables but I've tried setting up a variable early to reserve space then writing over it later but it never plays well with gc for some reason. |
Beta Was this translation helpful? Give feedback.
-
Importing a As @kjm1102 suggests, even more RAM-efficient is initialising a |
Beta Was this translation helpful? Give feedback.
-
You may want to try deleting the reference in sys.modules of im before you do del. You can try this after ...
sleep(0.1)
sys.modules.pop(f"/exports/output_frames{i}")
del frames,im; gc.collect() but memory fragmentation will still occur. |
Beta Was this translation helpful? Give feedback.
-
To put this into context the SSD1306 frame buffer is 1KiB in size. This is tiny. I have been developing micropython-touch on the Pico, one of the displays having a framebuf of 78,600 bytes. I have had no OOM problems. The more I think about this, the more convinced I am that the problem is the repeated invocation of the compiler. The approach I use is to create the frame buffer first, then perform all the imports, then start running code. That way the (huge) frame buffer is created before any RAM fragmentation can occur. Then the compiler gets all the remaining RAM to work in. Finally the code gets a look-in. |
Beta Was this translation helpful? Give feedback.
-
I am sorry for my poor code quality. I made something that writes frames from files to a display and I seriously can't figure out why it is getting a memory error. each frame file is the correct size to fit within its memory yet the memory usage just goes up and up until it stops working. here is the error
Traceback (most recent call last): File "<stdin>", line 30, in <module> MemoryError: memory allocation failed, allocating 396 bytes
here is the code:
Beta Was this translation helpful? Give feedback.
All reactions