how to count lines in a file ?

Jonathan Hogg jonathan at onegoodidea.com
Fri Jul 26 14:21:52 EDT 2002


On 26/7/2002 14:45, in article
Znc09.12549$724.4531 at atlpnn01.usenetserver.com, "Steve Holden"
<sholden at holdenweb.com> wrote:

> So what you appear to dislike is that there is now a *chance* that __del__()
> will be called on cyclic garbage, when there wasn't before.

Not quite. Any cycle containing an object with a __del__ method will be
skipped and left to languish in memory-limbo forever.

If the objects exist in a cycle then "logically" they must exist for ever.
Luckily, for most simple containers, throwing them away is semantically no
different from keeping them around - a dictionary or a list on it's own
doesn't do anything. However, if something has a __del__ method then
throwing it away requires executing some code which may have unknown
side-effects - so you can't do it.

At the very simplest level, the object's dictionary/slots may be meaningless
at the time that you would execute __del__ (because you're in the middle of
breaking all the cyclic references), so executing __del__ might cause
horrible things to happen.

It's a sort of philosophical thing. If you can be sure that having closed
the door, no-one will open it again then the room on the other side is
allowed to simply disappear ;-)

__del__ only has sensible semantics in the presence of reference counting.
Either have reference counting or throw away __del__. When it comes down to
it you gotta pick one or the other.

Jonathan




More information about the Python-list mailing list