How properly manage memory of this PyObject* array?? (C extension)

seberino at spawar.navy.mil seberino at spawar.navy.mil
Sun Jul 9 01:29:59 EDT 2006


Suppose a C extension locally built an array of PyObject* 's as
follows...

my_array = malloc(n * sizeof(PyObject*));
for (i = 0; i < n; i++) {
       my_array[i] = PyList_New(0);
}

Q1: Must I do a Py_DECREF(my_array[i]) on all elements
      before exiting this C extension function? (What if
     the elements got used in other objects?)

Q2: Must I do free(my_array); at end of function??  What if
my_array[i]'s are
      used in other objects so that I can't necessarily just
      nuke it!!!

Chris




More information about the Python-list mailing list