draft proposal for ref counting in D - BRIEF ROUNDUP

Michel Fortin michel.fortin at michelf.ca
Sat Oct 12 18:50:10 PDT 2013


On 2013-10-13 01:15:49 +0000, "deadalnix" <deadalnix at gmail.com> said:

> Can someone explain me what an autorelease pool is ?

A basic concept in Objective-C to make manual reference counting 
bearable. As things are moving to *automatic* reference counting now 
autorelease pools are becoming less important, but they remain there 
for backward compatibility and autoreleased objects must be handled 
correctly by ARC following to the existing conventions.

The concept is to have functions return autoreleased objects, objects 
pending release. Each time you autorelease an object, instead of the 
counter being decremented immediately, the object gets added to the 
autorelease pool and the pool decrement the counter later when it gets 
drained. So, when the caller gets an autoreleased object, it doesn't 
have to decrement the counter when it stopped using the object as a 
temporary, the object will be cleaned up automatically later, generally 
at the next iteration of the event loop. You only need to retain the 
object if you're storing it somewhere else than a local variable.

So this is what made manual reference counting bearable in Objective-C. 
Autorelease pool support is only useful and needed for correctly 
implementing ARC for Objective-C object types.

-- 
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca



More information about the Digitalmars-d mailing list