beginner's refcount questions

Jens Theisen jth02 at arcor.de
Sun Oct 29 19:30:53 EST 2006


Hello,

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()

foo()
print "done!"

prints

deled!
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