API/C memory mananegemnt problem
Hi everybody, I have a problem with Python/C API and memory management. I'm using Python 2.3.5 (#1, Jan 4 2006, 16:44:27) [GCC 4.0.2 20050901 (prerelease) (SUSE Linux)] on linux2 In my C-module I have a loop like this: *** int size=1000; output=(double *) calloc(size, sizeof(double)); py_output=PyList_New(0); for(i=0; isize; i++){ tmp=PyFloat_FromDouble(output[i]); PyList_Append(py_output, tmp); } free(outout); return py_output; *** It returns to python module a (very large) list. Problem: when I delete the list in python module (with python del statement) not all memory is relased. It look like all 1000 tmp PyFloat allocated in C code remain stored in memory. Somebody can help me? Thanks. marco -- http://mail.python.org/mailman/listinfo/python-list
API/C memory mananegemnt problem
Thank for your help. I have try to follow your suggestion but I seem to fail. Now my C-module (call it C_Core) code is: *** /* create_list function */ int size=1000; output=(double *) calloc(size, sizeof(double)); py_output=PyList_New(0); for(i=0; isize; i++){ tmp=PyFloat_FromDouble(output[i]); PyList_Append(py_output, tmp); Py_DECREF(tmp); // append adds a reference } free(outout); return py_output; ** with del statement all memory is relased, but I have a malformed list. In python shell: # Call C function an create a list alfa=C_Core.create_list() # check the list len(alfa) 1000 # OK alfa[1] Segmentation fault On the other size your last option with PyList_SET_ITEM(py_output, tmp) statement is quick, but I have still memory problem. Any idea? Thank a lot marco -- http://mail.python.org/mailman/listinfo/python-list