So my code for a pyboard v1.1 has been growing bigger and bigger. I have a class defined that deals with external SPI flash memory, so naturally it has a lot of attributes and methods in it. Its code size is "gigantic" relative to all other classes I have defined for other uses. Today I added yet another method to this flash memory class and bingo I hit a "memory allocation error". I did various tests involving commenting out other methods in the class, enough to determine that the new code was perfectly ok and that it was simply a matter of what looks to me like "too much code" in the class. I suspect the issue is something to do with the heap.
My work-around was to simply move the new method outside the class, without changing the code except for various namespace tweaks. It works just fine. After doing this and then using mem_info() I get:
stack: 1140 out of 15360
GC: total: 103360, used: 53632, free: 49728
No. of 1-blocks: 505, 2-blocks: 76, max blk sz: 112, max free sz: 530
It seems like there is still lots of RAM available. So my question is more curiosity. Am I running into some under-the-hood limitations of microPython vis-a-vis classes and objects?
Thanks
memory allocation error
Re: memory allocation error
Your heap is probably fragmented. See this thread for more details: viewtopic.php?f=2&t=7915&p=45461&hilit=collect#p45461
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: memory allocation error
Also read this in the official docs.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: memory allocation error
Similar issue on the Esp8266, this is my (possible) solution:
viewtopic.php?f=2&t=7097&start=10#p45915
viewtopic.php?f=2&t=7097&start=10#p45915
Paul Mulvey