On Sep 18, 2006, at 10:56 PM, Barry Warsaw wrote:


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.

Objective-C, or rather Cocoa, uses reference counting but with a twist. Cocoa as autorelease pools (class NSAutoreleasePool) any object that is inserted in an autorelease pool gets its refcount decreased when the pool is deleted. Furthermore the main event loop creates a new pool at the start of the loop and removes it at the end, cleaning up all autoreleased objects.

Most cocoa methods return borrowed references (which they can do because of autorelease pools). When you know you won't hang onto an object until after the current iteration of the eventloop you can savely ignore reference counting. Only when you store a reference to an object somewhere (such as in an instance variable) you have to worry about the refcount.

<rant class="mini">
The annoying part of Cocoa's refcounting scheme is that they, unlike python, don't have a GC to clean up loops. This causes several parts of the Cocoa framework to ignore refcounts to avoid creating loops, which is rather annoying when you write a bridge to Cocoa and want to hide reference counting details.
</rant>

Ronald

P.S. Apple is switching to a non-reference counting GC scheme in OSX 10.5 (http://www.apple.com/macosx/leopard/xcode.html).

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to