garbage collection / cyclic references

andrew cooke andrew at acooke.org
Sat Mar 21 12:59:56 EDT 2009


Aaron Brady wrote:
> My point is, that garbage collection is able to detect when there are
> no program-reachable references to an object.  Why not notify the
> programmer (the programmer's objects) when that happens?  If the
> object does still have other unreachable references, s/he should be
> informed of that too.

i think we're mixing python-specific and more general / java details, but,
as far as i understand things, state of the art (and particularly
generational) garbage collectors don't guarantee that objects will ever be
reclaimed.  this is a trade for efficiency, and it's a trade that seems to
be worthwhile and popular.

furthermore, you're mixing responsibilities for two logically separate
ideas just because a particular implementation happens to associate them,
which is not a good idea from a design pov.

i can remember, way back in the mists of time, using java finalizers for
doing this kind of thing.  and then learning that it was a bad idea.  once
i got over the initial frustration, it really hasn't been a problem.  i
haven't met a situation where i needed to tie resource management and
memory management together (except for interfacing with c code that does
not use the host language's gc - and i can imagine that for python this is
a very strong (perhaps *the*) argument for reference counting).

as an bonus example, consider object caching - a very common technique
that immediately breaks anything that associates other resources with
memory use.

just because, in one limited case, you can do something, doesn't mean it's
a good idea.

andrew





More information about the Python-list mailing list