Are there any caveats or tricks to using sys.stdin.read() and readline() in a way that preserves memory? I am seeing a memory leak ( I believe) when reading certain ASCII characters using sys.stdin.read(). I am running Micropython v1.18 on a Pico with RP2040.
Code: Select all
import sys
import gc
while True:
sys.stdin.read(1)
print (gc.mem_free())
Sending any combination of characters (b,e,f,n,r,s,t,v,x,y) results in a printout of free memory that does not change. Sending a character not on that list results in a decrease of free memory. If I use readline() instead, I see a decrease in available memory regardless of characters sent.
I have also tested this outside of an IDE (loading the pico with this code, disconnecting from Thonny, and using terminal) and see the same result, so I don't believe it is Thonny related.