Closed casoich closed 6 years ago
I now believe the leak to be in the .Color method (line 525 in the dotstar.c library) here:
// Given separate R, G, B, return a packed 32-bit color.
// Meh, mostly here for parity w/Arduino library.
static PyObject *Color(DotStarObject *self, PyObject *arg) {
uint8_t r, g, b;
PyObject *result;
if(!PyArg_ParseTuple(arg, "bbb", &r, &g, &b)) return NULL;
result = Py_BuildValue("I", (r << 16) | (g << 8) | b);
Py_INCREF(result);
return result;
}
I don't know enough about C to know what's leaking, but I have an equivalent method in python, that does not leak:
def RGBto32(rIn,gIn,bIn):
pass
return ( ( rIn << 16 ) | ( gIn << 8 ) | bIn )
(note the pass
is in there just to allow me to collapse the function in Sublime Text. :-) )
Yep, that seemed to fix it. Thanks for spotting!
Platform/operating system (i.e. Raspberry Pi with Raspbian operating system, Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): Raspberry Pi with Jessie operating system
Python version (run
python -version
orpython3 -version
): Python 2.7.9 (default, Mar 8 2015, 00:52:26)Error message you are receiving, including any Python exception traces: Memory leak in PyObject getPixelColor(DotStarObject self, PyObject *arg) *
List the steps to reproduce the problem below (if possible attach code or commands to run): LIST REPRO STEPS BELOW A routine that uses the getPixelColor function will cause an increase in memory usage in the
python
process, eventually causing the process to bail out. The snippet below can be altered by commenting the getPixelColor line in and out, and usingtop
to see the process memory heap.Included is the entire .py script if you wanted to try it for yourself. If you run it, try
python pixelmatrix.py flurry
pixelmatrix.py.zip