Where does all the RAM disappear?



  • When I check gc.mem_free() after restarting uiflow micropython I get about 80k on a Stickc and Stickc plus. Where is the other 430k?

    Jack
    PS With a bare metal firmware it's over 100k, same question.



  • Python is a scripting language. You need an interpreter that resides in ram to run the python code. You also need in-memory buffers to read scripts, interpret them, and run bytecode. Add that more program stack and network stack. If you write a program in, say, arduino and compile it, you will have almost all available RAM.



  • Got it, thanks Rob. Any idea how much for the interpreter, the buffers, the bytecode... ?

    Jack



  • in this screenshot you have how many stack are occupying the ram.

    https://docs.m5stack.com/image/base/APIKEY.webp

    If you need more free ram memory, probably you need compile micropython from scratch and change some parameters in source code.



  • @robalstona Interesting, thankyou.



  • I think an interesting option would be to "compile" the Python code on PC (like Arduino) and then transfer only binaries to the ESP32.



  • @mb You can use python cross compiler to compile source code into pseudo-executable code called bytecode. Which will not reduce the memory already used by python, but it will reduce the memory consumption by compiled .mpy code compared to the .py code itself and the code will be executed faster. In this case, the source code to bytecode translation process is skipped. But any change of source code need again crosscompile and transfer compiled files to device.

    That's why I like to create programs in micropython. Any change in the program takes a few seconds. (Compared to writing in arduino or esp-idf where every change in the code involves recompiling all the code from scratch and flashing and take some time which is too long for me). But something at the expense of something: faster program development at the expense of operating speed and memory usage.



  • @mb You need to read a bit about py and c++ difference