Search found 7 matches
- Wed Apr 27, 2022 9:37 pm
- Forum: Raspberry Pi microcontroller boards
- Topic: stdin memory leak
- Replies: 14
- Views: 10583
Re: stdin memory leak
Do you have any suggestions on good ways to pre-allocate memory for strings or release memory used for string functions? Or is the best method to gc.collect() after I'm done decoding into a string, similar to below? import sys import gc b = bytearray(1) def read(): sys.stdin.readinto(b) return b.dec...
- Wed Apr 27, 2022 7:09 pm
- Forum: Raspberry Pi microcontroller boards
- Topic: stdin memory leak
- Replies: 14
- Views: 10583
Re: stdin memory leak
Thank you very much for all your advice and insight, I agree. I need to be very aware of memory usage in the functionality I choose to use, especially with strings. Circuitpython must have been releasing memory without me realizing it. And when I introduced a second thread in micropython, the increa...
- Wed Apr 27, 2022 6:25 pm
- Forum: Raspberry Pi microcontroller boards
- Topic: stdin memory leak
- Replies: 14
- Views: 10583
Re: stdin memory leak
Unfortunately, no multicore support yet on circuitpython, hence the switch. My code in circuitpython was a single routine that scanned the port, grabbed sensor values, and reported back, obviously loop time greatly held back by how long the onewire sensor was taking to update. For anyone curious: He...
- Wed Apr 27, 2022 4:45 pm
- Forum: Raspberry Pi microcontroller boards
- Topic: stdin memory leak
- Replies: 14
- Views: 10583
Re: stdin memory leak
Thanks again - this makes sense. I'll try some nightly builds. I am converting this code from circuitpython and did not notice memory allocation issues with essentially the same code. Dynamic memory allocation must be handled very differently there. Is the safe path forward is to avoid most string c...
- Wed Apr 27, 2022 3:28 pm
- Forum: Raspberry Pi microcontroller boards
- Topic: stdin memory leak
- Replies: 14
- Views: 10583
Re: stdin memory leak
Am I doing something similar when attempting to decode/concatenate the byte array into a string? I see a similar "memory loss" issue when attempting to convert to string or concatenate the bytes to a string for comparison later in the program. import sys import gc b = bytearray(1) string = "" while ...
- Wed Apr 27, 2022 2:49 pm
- Forum: Raspberry Pi microcontroller boards
- Topic: stdin memory leak
- Replies: 14
- Views: 10583
Re: stdin memory leak
Thank you for the helpful explanation! This is exactly what I needed. This code is actually just a snippet from a larger application, and I did try gc.collect(), but it seemed to cause instability in the second thread (using the second core of the RP4040 to ping a sensor and update a global). I have...
- Wed Apr 27, 2022 1:55 pm
- Forum: Raspberry Pi microcontroller boards
- Topic: stdin memory leak
- Replies: 14
- Views: 10583
stdin memory leak
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. import sys import gc while True: sys.std...