Is this a leaker?

Thomas Wouters thomas at xs4all.nl
Fri Jun 30 10:32:28 EDT 2000


On Fri, 30 Jun 2000 09:26:59 -0500, Arinté <n at n.com> wrote:
>> This depends on how you document your function :) If you document it as
>> returning a borrowed reference, the caller should not DECREF the returned
>> value. If you document it as returning a new reference, it should take
>care
>> of the DECREF itself. In this case, it doesn't make sense to return a
>> borrowed reference: If you do a DECREF on the fresly-created
>> Py_BuildValue()-object, it'll end up destroyed !

>I was speaking of returns to python scripts.  All of the 'return
>Py_BuildValue()' return to python scripts.  I don't have to decref in py
>script files do I?

Nope, you don't. Python scripts (or rather, the bytecode interpreter)
automatically DECREF everything they lose a reference to, DECREFing objects
left and right. Note that this means you should never return a borrowed
reference to a Python caller ! If you do, you might end up with a dangling
pointer yourself.

Thomas.



More information about the Python-list mailing list