Python C Extensions

MRAB python at mrabarnett.plus.com
Thu Feb 24 12:46:29 EST 2011


On 24/02/2011 16:46, aken8062 at yahoo.com wrote:
> Thank you very much, it worked.
> I thought the PyDict_SetItem should assume ownership
> of the passed object and decrease it's reference count (I do not know
> why).
>
> Does this also go for the Lists ? Should anything inserted into list
> also
> be DECRED-ed ?
>
> Thank you again for reply.
>
[snip]
The pattern is that calls which create an object will return that
object with a refcount of 1, and calls which 'store' an object, for
example, PyDict_SetItem(...) and PyList_Append(...) will increment the
refcount of the stored object to ensure that it won't be garbage
collected.

When in doubt, try stepping through the code in a debugger. You'll see
that storing an object will cause its refcount to be incremented.



More information about the Python-list mailing list