[Pythonmac-SIG] INCREMENTING & DECREMENTING PyObjects

Jack Jansen jack@oratrix.nl
Tue, 16 Jan 2001 10:11:46 +0100


>     Some questions:
>         If I Py_DECREF a Class Instance held by the C++ GUI, do I have to
> Py_DECREF all its fields?

In general: yes. Normally if you store a reference to an object anywhere you 
should INCCREF it, if you delete the reference again you DECREF it.

>         If I do not create PyObject in the C++ GUI, but I ask its reference to
> the  Python Interpreter, what do I get : A copy of the reference of the
>                 object? What reference count does it hold?? Do I have to
> Py_INCREF , for further use into the C++ GUI??

Normally not, but it depends on the function you use to obtain the reference. 
Almost all of the core Python functions will do the INCREF before returning 
the object.

You should probably read "Extending and Embedding Python", which you can find 
on www.python.org, which has the exact details about increffing and decreffing.
--
Jack Jansen             | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++
www.oratrix.nl/~jack    | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm