Garbage collection

Hrvoje Niksic hniksic at xemacs.org
Tue Feb 19 04:47:38 EST 2008


Simon Pickles <sipickles at googlemail.com> writes:

> Ken wrote:
>> What is your __del__ method doing?
>>   
> Actually, nothing but printing a message when the object is deleted,
> just morbid curiosity.
>
> I've yet to see one of the destructor messages, tho....

Do your objects participate in reference cycles?  In that case they
are deallocated by the cycle collector, and the cycle collector
doesn't invoke __del__.

>>> class X(object):
...   def __del__(self): print "gone"
...
>>> a = X()
>>> a = 1
gone
>>> b = X()
>>> b.someslot = b
>>> b = 1
>>> import gc
>>> gc.collect()
0
>>> 



More information about the Python-list mailing list