I have a motion detection script that uses the Picamera library. I use the PicameraCircularIO stream object, that inherits from the CircularIO class (still a class form the Picamera library), which inherits from the native Python BytesIO class.
The problem is that when recording into the circular stream and then writing the content of the stream on the disk, the memory does not get cleared.
After the stream has been written on the disk, this is what I do:
stream.seek(0)
stream.truncate()
I have also tried calling stream.flush()
and/or closing the stream: stream.close()
, but it did not help.
I have also tried removing all references to the stream for it to be garbage collected (even though it makes no sense to do that, since truncating the stream to the size 0 should normally do the job...). The stream is in an array, so I did del streams[index]
. It did not work, so I also tried calling the garbage collector manually: gc.collect()
, with no effect.
It is only the bytes that are being writtin in the stream that are being counted in the memory, not the stream size. So for example, if 2125000 bytes are written into the stream and then I truncate it, there will still be 2125000 bytes in the memory.
Any tip/trick/answer is appreciated.
Cheers!