__del__ methods
Robert Rawlins
robert.rawlins at thinkbluemedia.co.uk
Sat Jul 19 05:43:54 EDT 2008
> Yes.
>
> "Objects that have __del__() methods and are part of a reference cycle
> cause the entire reference cycle to be uncollectable, including
> objects not necessarily in the cycle but reachable only from it.
> Python doesn't collect such cycles automatically because, in general,
> it isn't possible for Python to guess a safe order in which to run the
> __del__() methods."
>
> The uncollectable objects are stored in gc.garbage and will not be
> freed until their reference cycles are broken and they are removed
> from that list.
Ok, guys,
I've just recently (in the past week) started using the __del__ method to
log class instance destruction so I can keep a track of when objects are
created and destroyed, in order to help me trace and fix memory leaks.
Are you saying that on the adverse side to this, __del__ may in fact be the
CAUSE of a memory leak within my application?
If this is the case and __del__ creates such a vulnerability within the
application, and apparently isn't all that reliable anyway, why is it still
part of the python platform?
Cheers,
Robert
More information about the Python-list
mailing list