[Openmcl-devel] Allocating temporary nsstrings
raffaelcavallaro at mac.com
Sun Mar 13 10:28:04 CDT 2011
On Mar 13, 2011, at 10:50 AM, Paul Krueger wrote:
> It's never been entirely clear to me exactly how these Objective C class constructors are implemented. Do they re-use memory from some pool or just return an autoreleased object?
In Objective-C they're referred to as "Convenience Constructors" and they work, as you suspected, by calling autorelease on the newly allocated object before returning:
In Apple's docs:
"The convenience constructor method returns an autoreleased object, so you don't have to send another release."
in the GNUStep docs:
A special case of object transfer occurs when a convenience constructor is called (instead of alloc followed by init) to create an object. (Convenience constructors are class methods that create a new instance and do not start with "new".) In this case, since the convenience method is the one calling alloc, it is responsible for releasing it, and it does so by calling autorelease before returning. "
raffaelcavallaro at me.com
More information about the Openmcl-devel