[Openmcl-devel] Allocating temporary nsstrings
Raffael Cavallaro
raffaelcavallaro at mac.com
Sun Mar 13 08:28:04 PDT 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."
from:
<http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html%23//apple_ref/doc/uid/TP40004447-SW1>
in the GNUStep docs:
"Convenience Constructors
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. "
from:
<http://www.gnustep.org/resources/documentation/Developer/Base/ProgrammingManual/manual_3.html>
warmest regards,
Ralph
Raffael Cavallaro
raffaelcavallaro at me.com
More information about the Openmcl-devel
mailing list