Misc questions about type objects and Python 3.0

sismex01 at hebmex.com sismex01 at hebmex.com
Tue Oct 8 09:28:05 EDT 2002


> From: David Brown [mailto:david at no.westcontrol.spam.com]
> 
> "Simon Brunning" <SBrunning at trisystems.co.uk> wrote in message
> news:mailman.1034073671.12754.python-list at python.org...
> >
> > Jython doesn't use reference counting and it's hardly 
> > *wildly* different from CPython. Subtly different, yes,
> > but you don't notice the difference very often, unless
> > you are prone to de-referencing open files, or that
> > sort of thing.
> >
> 
> 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.

Wrong. You're confusing garbage collection with reference counting.
The latter, reference counting, is used IN CPYTHON ONLY, not
in Jython.  Jython uses Java's native garbage collection which
if I recall correctly is based on a mark-and-sweep algorithm.

CPython uses reference counting as a measure to find if an
object is still accessible; when the rc drops to 0, the object
is automagically collected (previously, any __del__ method is
called).

Object containers pass through a garbage collection phase,
where any mutual reference loops are solved which permit any
objects caught in the loop to be correctly destroyed, but
this is a separate process, and CPython can be compiled without
the gc module which implements it.

> 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?

Nope, it uses Java's own GC.

Good luck :-)

-gustavo













More information about the Python-list mailing list