MemoryError: #11542
-
In my code, i am getting a 'MemoryError:' with no further explanation. Here is a bit of info : +1: 3.4.0: MicroPython v1.20.0 on 2023-04-26 I'm using Thonny IDE. First off, the memory error occurs in my main loop in random times and prints ONLY MemoryError: with no extended information. I am importing sdcard.py (MicroPython library for SPI bus) I tracked it down to one particular offending line of code. : The line where i open in 'w' mode. I commented out any actual writing. I open the file in 'w' mode, and then next line, close the file. If i do that, then at some point later in my main loop code, the program will spit out a memoryerror: If i don't have the SDcard in the slot, it will write to the Flash, and there are never any errors in the Main Loop. If i put the SDcard into the slot, and save the settings, it WILL SUCCESSFULLY write the config file to SDcard, and everything worked as expected, but then in my main loop ill get a memoryerror: at some point within the next second or so... If i ignore it, everything keeps running and there seems to be no lingering issues. Gives eventual memory error
if i change it to 'r' mode, it will NOT give me a memoryerror:
So, now that i tracked it down, the question is why is it happening.. Does that action of open a file (SPI bus SDcard) for write mode eat up more memory which is then causing issues later down the line in my code??? Or, am i not doing something i should be doing to prevent this situation from occurring. When I have an SDcard present, i then Mount it utilizing the sdcard.py and when im done writing i unmount the SDcard. But, the error WILL occur whether or not i leave the mount open, or close the mount after the open in write mode. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This doesn't call the close method, so the file isn't closed. f.close() # Have to have () to call the method. |
Beta Was this translation helpful? Give feedback.
This doesn't call the close method, so the file isn't closed.