Does python hate cathy?

Hrvoje Niksic hniksic at xemacs.org
Tue Mar 25 14:07:55 EDT 2008


Marc 'BlackJack' Rintsch <bj_666 at gmx.net> writes:

> On Tue, 25 Mar 2008 14:58:51 +0000, Edward A. Falk wrote:
>
>> In article <mailman.2308.1206425945.9267.python-list at python.org>,
>> Patrick Mullen <saluk64007 at gmail.com> wrote:
>> 
>>>Then again, I can count the number of times I have ever needed __del__
>>>with no fingers (never used it!).  Still, quite interesting to
>>>explore.
>> 
>> I used it once, for an object that had a doubly-linked list.
>> The __del__() method walked the list, setting all the elements'
>> prev/next pointers to None to make sure the elements of the list would
>> get garbage-collected.
>
> Without the `__del__()` the elements would get garbage collected just
> fine.

It gets even worse than that: the __del__ method actually *prevents*
objects that participate in cycles from getting garbage-collected.
Python's GC doesn't deallocate objects that define __del__.  (The way
to handle those is to grep for them in gc.garbage, break the cycles in
a way that works for the application -- e.g. by removing the prev and
next references -- and finally del gc.garbage[:].)



More information about the Python-list mailing list