C extension reference count confusion (always)

Bob Greschke bob at passcal.nmt.edu
Tue Aug 7 20:46:38 CEST 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
to create a NumPy array using the malloc()ed memory as its first
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,
when, where to I have to call to release all of the memory?  That part
definitely not working.  Do I have to keep track of the malloc()ed
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,
Do I have to just do a Py_DECREF() on the returned NumPy array?
Both?  Neither??

I WILL understand this one day. :-)



More information about the Python-list mailing list