MEmoryError: memory allocation failed
-
Re: [MemoryError: memory allocation failed](allocating 2048 bytes - LOPY - 1.2.0.b1)
Hello, I have this error too, but I want to know if this can work when the error comes out in the execution time, not the compilation, or how can I fix that.
Thanks in Advance
-
Depends.
2k on a LoPy is a lot of memory. If it occurs during compilation time, precompiling your code with mpy_cross is the solution.
Otherwise it is not that easy. You have to reduce memory fragmentation.
You can see the fragmentation withmicropython.mem_info()
Precompile as many files as you can. So the memory of the LoPy is not fragmented after boot time. Allocate huge buffers as early as you can. Reuse them instead of reallocate.You can try to call the garbage collector in front of your memory allocation. But this does not help in many situations. The garbage collector does not relocated objects in use, so the memory is still fragmented. If there is a background thread, it may fill your memory faster than you can free it. For example if it calculate float objects in a loop.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login