Misc questions about type objects and Python 3.0

Simon Brunning SBrunning at trisystems.co.uk
Tue Oct 8 09:00:34 EDT 2002


> From:	David Brown [SMTP:david at no.westcontrol.spam.com]
> How does the garbage collection work then?  Somehow you have to keep track
> of whether an object is still in use or not.  (Again, correct me if I'm
> wrong here).  Every time a reference is created to an object in CPython,
> the
> reference count is incremented, when a reference is removed it is
> decremented - if the count is 0, the object is no longer accessible and
> can
> therefore be collected on the next garbage collection pass.  As far as I
> know, the only other way to do this is to regularly scan through all
> current
> pointers to see what's in use - if there are any objects around that
> aren't
> pointed to, they can be garbage collected.  This has got to be a much less
> efficient method.  In JPython, presumably it is the underlying JVM that
> does
> the garbage collection - maybe it uses reference counting even though the
> Jython layer doesn't have to deal with it?
 
As you suggest, Jython uses the underlying JVM's garbage collection. This
can vary from JVM to JVM, but most use some form of mark-and-sweep, I think.

The big difference from the point of view of some one using Jython is that
objects do not get removed as soon as they are no longer referenced, but
whenever GC decides to get rid of them. This may be very soon, or never -
it's up to the JVM.

With CPython's reference counting mechanism, the object is destroyed
immediately its reference count drops to zero, though it is wise not to
depend on this, since the implementation is free to change. Note that
CPython uses GS as well as reference counting, to catch cycles.

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning at trisystems.co.uk




-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.




More information about the Python-list mailing list