adafruit / DotStarPiPainter

Light painting project for Raspberry Pi + DotStar strips
14 stars 6 forks source link

Memory leak? #1

Open etarts opened 7 years ago

etarts commented 7 years ago

I modified the code slightly to just go through a bunch of images and repeat. This is for a museum installation and must run continuously. It seems that the imagebuf doesn't get freed so eventually I run out of memory. I don't know enough about how Python manages memory to fix this. Can you confirm this leak exists and find a fix? Just run "top" along side it and watch the memory usage as you load new images.

Thanks for the great software! Ed

PaintYourDragon commented 7 years ago

Does it in fact crash after a while, or does memory use just get really big but it keeps running? If the latter, most likely a case of the Python garbage collector not running until actually needed.

etarts commented 7 years ago

It does crash. That's why I noticed it.

On Oct 18, 2016 3:50 PM, "Paint Your Dragon" notifications@github.com wrote:

Does it in fact crash after a while, or does memory use just get really big but it keeps running? If the latter, most likely a case of the Python garbage collector not running until actually needed.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/adafruit/DotStarPiPainter/issues/1#issuecomment-254662197, or mute the thread https://github.com/notifications/unsubscribe-auth/AFGd_Wn5J_rbgNs7XfytDkB7h-aBbxbVks5q1U1PgaJpZM4KZJwK .

etarts commented 7 years ago

There seems to be an issue also with the RGB order. Setting it does affect the colors when explicitly setting colors like in the loading / proccessing sequence, but not the order of the processed image. I had to alter the C code in lightpaint.c to swap the red and green for my newer RGB stick to get the color order right.

Ed Tannenbaum Electrons Tamed for the Arts PO Box 398 Crockett, CA 94525 www.et-arts.com +1 510 787-1567

On Tue, Oct 18, 2016 at 6:08 PM, Ed Tannenbaum et@et-arts.com wrote:

It does crash. That's why I noticed it.

On Oct 18, 2016 3:50 PM, "Paint Your Dragon" notifications@github.com wrote:

Does it in fact crash after a while, or does memory use just get really big but it keeps running? If the latter, most likely a case of the Python garbage collector not running until actually needed.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/adafruit/DotStarPiPainter/issues/1#issuecomment-254662197, or mute the thread https://github.com/notifications/unsubscribe-auth/AFGd_Wn5J_rbgNs7XfytDkB7h-aBbxbVks5q1U1PgaJpZM4KZJwK .

PaintYourDragon commented 7 years ago

Python modules are new territory for me, so I might be handling references wrong WRT allocation and deallocation. Looking at some others' code, here's something that might be worth trying...in lightpaint.c, toward the end of the LightPaint_new() function, comment out this line: Py_INCREF(self); // Done, save object Mmmmight need to add a Py_DECREF(self) first thing in the else case that immediately follows. Basically, I'm wondering if the first reference is implicit, and the INCREF may be doubling up and thus never allowing the object to be freed. Worth trying!

etarts commented 7 years ago

That seems to have plugged it! I just commented out the Py_INCREF(self). No DECREF necessary. Excellent! Thanks!

The RGB order bug still stands but for me is solved. I can't tell where that happens. Either the parsing and treating of the order argument in lightpaint, starting at line 74, or the double use of the order cancelling itself out? It works in setPixelColor() in DotStar.

Ed Tannenbaum Electrons Tamed for the Arts PO Box 398 Crockett, CA 94525 www.et-arts.com +1 510 787-1567

On Wed, Oct 19, 2016 at 2:43 PM, Paint Your Dragon <notifications@github.com

wrote:

Python modules are new territory for me, so I might be handling references wrong WRT allocation and deallocation. Looking at some others' code, here's something that might be worth trying...in lightpaint.c, toward the end of the LightPaint_new() function, comment out this line: Py_INCREF(self); // Done, save object Mmmmight need to add a Py_DECREF(self) first thing in the else case that immediately follows. Basically, I'm wondering if the first reference is implicit, and the INCREF may be doubling up and thus never allowing the object to be freed. Worth trying!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/adafruit/DotStarPiPainter/issues/1#issuecomment-254949836, or mute the thread https://github.com/notifications/unsubscribe-auth/AFGd_QevY50EedB2EnI-OOJRAZlD4PQzks5q1o8CgaJpZM4KZJwK .