[Python-3000] Delayed reference counting idea

Barry Warsaw barry at python.org
Mon Sep 18 22:15:47 CEST 2006

Hash: SHA1

On Sep 18, 2006, at 3:56 PM, Raymond Hettinger wrote:

> * An easier C API would significantly benefit the language in terms of
> more extensions being available and in terms of increased reliability
> for those extensions.  The current refcount scheme results in  
> pervasive
> refleak bugs and subsequent, interminable bughunts.  It adds to code
> verbosity/complexity and makes it tricky for beginning extension  
> writers
> to get their first apps done correctly.  IOW, I agree that GC without
> refcounts will make it easier to write good C code.
> * I doubt the anecdotal comments about Boehm GC with respect to
> performance.  It may be better or it may be worse.  While I think the
> latter is more likely, only an implementation patch will tell the  
> tale.
> * At my company, we write real-time apps that benefit from the current
> refcounting scheme.  We would have to stick with Py2.x unless Boehm GC
> can be implemented without periodically killing responsiveness.

We'd be in the same boat.  While I agree with Raymond that it can be  
quite difficult to get C code to be refcount-correct, I wonder if  
there aren't tools or other debugging aids we can develop that will  
at least help debug when problems occur.  Not that I have any bright  
ideas here, but as an example, one of the things we do when our app  
exits (it's potentially long running, but never daemonic) is to  
stroll through the list of all live objects, checking their refcounts  
against expected values.  Of course we only do this in debug builds,  
but right now in our dev tree I'm looking at an issue where a central  
object has a few hundred more refcounts than expected at program exit.

The really tricky thing about refcounting is making sure all the exit  
conditions out of a function are refcount correct.  Usually these  
involve error or exception conditions, and they can be a bear to get  
right.  Make you want to write the goto-considered-useful rant all  
over again. :)  Would a garbage collection interface make this easier  
(because you could ignore all that) or would you be trading that off  
for things like gcpro in Emacs, which can be just as harmful if you  
screw then up?

- -Barry

Version: GnuPG v1.4.5 (Darwin)


More information about the Python-3000 mailing list