[Python-3000] Delayed reference counting idea

Barry Warsaw barry at python.org
Mon Sep 18 22:56:19 CEST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sep 18, 2006, at 4:33 PM, Jim Jewett wrote:

> On 9/18/06, Barry Warsaw <barry at python.org> wrote:
>
>>  ... I agree with Raymond that it can be quite difficult to get
>> C code to be refcount-correct, ...
>
> How much of this (particularly for beginners) is remembering the
> refcount affects of standard functions?  Could this be avoided by just
> always using the more abstract interface?  (Sequence instead of List,
> Mapping instead of Dict)

I think that may be part of it (I've mentioned this before), but our  
C API code wasn't written by beginners, and while we don't have any  
known refcounting problems in production code, during development one  
or two can slip through.  I don't think that the above is the major  
contributor.

>> 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.
>
> Would it solve this problem if there were a PyTEMPREF that magically
> treated the refcount as an automatic variable?  (It increfed
> immediately, and decrefed whenever the function exited, without the
> user having to track this manually.)
>
> Would it help enough to justify a pre-processing requirement?

I don't know, I hate macros. :)

<talking from="my ass">
It's been a long while since I programmed on the NeXT, so Mac folks  
here please chime in, but isn't there some Foundation idiom where  
temporary Objective-C objects didn't need to be explicitly released  
if their lifetime was exactly the duration of the function in which  
they were created?  ISTR something like the main event loop tracking  
such refcount=1 objects and deleting them automatically the next time  
through the loop.  Since Python has a main loop, I wonder if the same  
kind of trick couldn't be done here.

IOW, if you're just creating an object temporarily, you never need to  
explicitly decref it because the main eval loop would do it for you.   
Dang I wish I could remember the details.
</talking>

Something like that, where you didn't have to track all objects  
through all exit conditions would probably help.
- -Barry

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)

iQCVAwUBRQ8H83EjvBPtnXfVAQIz5wP+JUJF3fwYIZ6fUmG4PkpyE8K+oOflCQYE
vjBSa4vaCkX8fJvAZzwH5VgFoOEJ6WxLwagkJvFmVdCLDNgs2TwJF+cT45qJYCLF
cWbcNAtesxMVZIUMjtUDpQLoSw/1CTuGbCdymqEuteF8IRZEJP5Usv1c6ytS5LJK
cuLWyArvNeo=
=UDIj
-----END PGP SIGNATURE-----


More information about the Python-3000 mailing list