beginner's refcount questions

Jens Theisen jth02 at
Mon Oct 30 01:30:53 CET 2006


python uses gc only where refcounts alone haven't yet done the
job. Thus, the following code

class Foo:
    def __del__(self):
        print "deled!"

def foo():
    f = Foo()

print "done!"



and not the other way round.

In c++, this is a central technique used for all sorts of tasks,
whereas in garbage collected languages it's usually not available.

Is there a reason not to rely on this in Python? For example, are
there alternative Python implementations that behave differently?  Or
some other subtle problems?

And some other minor question: Is there a way to query the use count
of an object? This would be useful for debugging and testing.

Cheers, Jens

More information about the Python-list mailing list