-
Notifications
You must be signed in to change notification settings - Fork 1.3k
MemoryError
with simple imports on Pico W on 9.0.0-alpha6
#8736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm thinking I'm missing something obvious, I can't seem to reproduce this. import gc
print("Before import", gc.mem_free())
try:
import adafruit_datetime
# from adafruit_datetime import datetime
except:
pass
print("After import", gc.mem_free())
EDIT: I just noticed that I missed pasting in the device/version banner somehow...
|
That is strange, there is literally nothing else on my Pico unit that ran before code I posted. I don't think it can be caused by some physical damage to my Pico, can it? I used the latest build, downloaded jsut before posting Issue, and latest version of |
Anything in |
Are you using the .py or the .mpy version of |
@deshipu Empty @dhalbert I use EDIT 1: @RetiredWizard are you sure you have import gc
print("Before import", gc.mem_free())
try:
import adafruit_datetime
# from adafruit_datetime import datetime
except Exception as e:
print(e)
print("After import", gc.mem_free()) |
The .py version has to be compiled, and that can cause fragmentation, even if the RAM eventually used is about the same. |
I believe this could also happen when trying to execute user code, not only when importing libraries. Also, which is important, it used to work back in 8.2.9 and Pico W is a very popular board. I think it will happen to a lot of people when 9.0.0 comes out of alpha. I guess one could avoid that by compiling user code, but if I am correct it is not a intended use case. |
I was not importing the .py version of the library. I had considered it might have been a python library issue and tried using the .mpy. With the .py library in /lib/, I don't get the memory allocation error but I do see the high memory use: |
MicroPython is doing some split-heap tuning, which we could test out: #8729 |
The after number after the exception is a red herring because I'm looking into why the import process doesn't have enough memory. |
So, I think the addition of USB host in 9.x is the main cause of this regression (not the split heap stuff). It takes ~12k extra static RAM. At least 5k of that is code that needs to run even when the flash is being accessed.
LWIP and picodvi also have large RAM footprints even when they aren't in use as well. I think that using |
CircuitPython version
Code/REPL
Behavior
Importing some libs on 8.2.9 works as expected, and allocates only a small portion of memory, the same code/imports on 9.0.0-alpha6 errors with
MemoryError
, and despite not importing the module uses nearly all available memory.From my testing this does not happen on ESP32-S2, but maybe this is due to the higher amount of memory on these boards.
Description
Importing whole library on 8.2.9.

Importing only

datetime
class on 8.2.9.Importing whole library on 9.0.0-alpha6.

Importing only
datetime
class on 9.0.0-alpha6.Notice how despite not importing the lib successfully, the
gc.mem_free()
returns a 4k (I guess bytes).Additional information
My guess is, CircuitPython 9.x.x changed something regarding memory allocation. I was able to find this live from Adafruits YT channel, when they show something that looks like the problem presented here.
The text was updated successfully, but these errors were encountered: