Hello,
Is it possible to remove a circuitpython module from RAM that has been imported?
Example : 'import neopixel'
and as soon as you don't need the module any more in the code do 'del neopixel'.
I did a test and checked with 'gc.mem_free()', but after 'del module_name', the amount of memory available is even lower.
I am not sure if I have made myself clear.
Can you help me?
saving memory on Pico and other boards
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- AmazingCircuitPythonFR35
- Posts: 99
- Joined: Thu Feb 05, 2015 10:18 am
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: saving memory on Pico and other boards
MikeB35,
The cleanest option would be not to use a public global variable when accessing the modules. Keep them in custom functions so that when you exit the function the memory is freed up.
Alternatively if you want to explore the road not taken something along the lines of:
should delete the module, but it might be too messy for gc to relize the gains nor is it recommended.
The cleanest option would be not to use a public global variable when accessing the modules. Keep them in custom functions so that when you exit the function the memory is freed up.
Alternatively if you want to explore the road not taken something along the lines of:
Code: Select all
del sys.modules[module_name]
- AmazingCircuitPythonFR35
- Posts: 99
- Joined: Thu Feb 05, 2015 10:18 am
Re: saving memory on Pico and other boards
mikeysklar wrote:MikeB35,
The cleanest option would be not to use a public global variable when accessing the modules. Keep them in custom functions so that when you exit the function the memory is freed up.
Alternatively if you want to explore the road not taken something along the lines of:
should delete the module, but it might be too messy for gc to relize the gains nor is it recommended.Code: Select all
del sys.modules[module_name]
Thanks a lot for your answer. I will follow your advice.
Mike
Please be positive and constructive with your questions and comments.