How properly manage memory of this PyObject* array?? (C extension)
seberino at spawar.navy.mil
seberino at spawar.navy.mil
Fri Jul 14 02:16:59 EDT 2006
> It's quite simple, really: You malloc it, you free it.
John - I hope you don't mind that I really want to make sure I
understand your
good wisdom in this area by asking for clarification....
ASSUMPTIONS:
1. As long as we properly handle the reference counting of PyObjects
then
memory management is taken care of for us. (i.e. You don't ever
use the 'free' command explicitly on a PyObject* but let Python
garbage collector
do the final freeing.)
2. All malloc'd stuff in C must be freed with free command. (Python
garbage
collector is limited to PyObjects. It won't free non-Python stuff
for us
like int arrays, char* strings, etc.)
....
Now it would appear that if you **malloc an array of PyObjects**
(call it FOO[]) then you have an ambiguity....
The PyObject elements will be freed *for us* eventually by garbage
collector.
Hence, we can't ever do 'free(FOO); ' because we don't know when
garbage collector will free FOO[0], FOO[1], FOO[2], etc.
Chris
More information about the Python-list
mailing list