C extension reference count confusion (always)

Bob Greschke bob at passcal.nmt.edu
Tue Aug 7 14:46:38 EDT 2001


- OK. I have a Python program that call a C extension function.
- The C function malloc()s a large chunk of memory for use as
an integer array.
- The C function then uses the NumPy function
PyArray_FromDimsAndData()
to create a NumPy array using the malloc()ed memory as its first
address,
and then calls another C function to fill up the malloc()ed/NumPy
array with data.
- The extension function then returns the NumPy array.  This all seems
to work fine.
- After I am finished with the NumPy array (plotting the values) who,
what
when, where to I have to call to release all of the memory?  That part
is
definitely not working.  Do I have to keep track of the malloc()ed
memory's
address and call a C extension function to free() the memory
(actually, I
could use the address from one of the NumPy object's struct members,
huh?)?
Do I have to just do a Py_DECREF() on the returned NumPy array?
Both?  Neither??

I WILL understand this one day. :-)

Thanks!

Bob






More information about the Python-list mailing list