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

seberino at spawar.navy.mil seberino at spawar.navy.mil
Mon Jul 17 23:45:15 EDT 2006


> Let's try reductio ad adsurdum on that one. Suppose that instead of
> filling in a malloced chunk of memory, you had stored those gizmoids in
> local variables foo0, foo1, foo2, etc. Using your reasoning: we can't
> ever return from our function (which frees up the stack memory
> containing foo0 etc) because we don't know when garbage collector will
> free foo0 etc. Avoiding that problem would require a Python/C API
> function with a name like Py_AwaitGarbageCollection() ... but there
> isn't one.

There are 2 memory components that make up a Python object.
First, there is the object in memory itself.  Secondly, there
is the 4 bytes or so that hold the address to the object in memory.
(the 'pointer')

I think what I hear you saying is that garbage collection has
to automagically take care of my second component above as well.

So can I assume you are also saying our original malloc'd pointer
to Python objects will be take care of as well as the objects?
(Hence, no free(my_array) necessary?)
(Only Py_INCREFs and Py_DECREFs need apply?)

Chris




More information about the Python-list mailing list