[Openmcl-devel] Allocating temporary nsstrings

Raffael Cavallaro raffaelcavallaro at mac.com
Sat Mar 12 20:38:24 PST 2011

On Mar 12, 2011, at 9:52 PM, Ron Garret wrote:

> but I don't know how to stack allocate an instance of an ObjC class, or if that's even possible

As far as I know, all objective-c objects are heap allocated (although blocks are also technically objective-c objects and they're initially stack allocated for efficiency and only copied to the heap if necessary).

The objective-c idiom is autorelease pools combined with autorelease. Clozure CL has ccl::with-autorelease-pool, so just allocate your temporary objects and call autorelease on them inside the scope of a with-autorelease-pool form:

? (ccl::with-autorelease-pool
       (let ((nsstr (#/autorelease (objc:make-nsstring "-12"))))
         (#/decimalNumberWithString: ns:ns-decimal-number nsstr))))

warmest regards,


Raffael Cavallaro
raffaelcavallaro at me.com

More information about the Openmcl-devel mailing list