Decrementing a reference counter...

Fredrik Lundh fredrik at pythonware.com
Sun Oct 10 10:30:03 EDT 1999


Olivier Deckmyn <olivier.deckmyn at mail.dotcom.fr> wrote:
> def toto(self, titi):
>     self.myTiti=titi
>     dec_refcount(titi) # To avoid circular reference
> 
> Of course, I wonder about the existence and syntax of a "dec_refcount"
> function. I know it is dangerous ; but it is the case where "I know what
> I am doing :)"

no, you don't ;-)

or perhaps: yes, it's spelled "del".

if you want the caller to hand over
the ownership, it should delete its
own reference:

    object.toto(titi)
    del titi # I don't need this

or maybe:

    object.toto(titi)
    titi = None # I don't need this

(after all, if you cannot trust it to
remember that, how on earth can
you trust it to not do anything with
the object it passed to toto?)

(alright, you could perhaps monkey
around with the call stack, but along
that road lies madness... ;-)

</F>





More information about the Python-list mailing list