[Openmcl-devel] Determining OSX version at runtime

Raffael Cavallaro raffaelcavallaro at mac.com
Fri Aug 27 15:42:54 UTC 2010

On Aug 27, 2010, at 11:13 AM, Paul Krueger wrote:

> Hmmm... I would have assumed that like most objects returned by functions you would have needed to explicitly #/retain the NSArray returned by #/allFrameworks

Convenience methods (i.e., any object creation that doesn't involve an explicit alloc, or copy) generally return autoreleased objects, so you need to have a pool in place or they'll just leak.

This is masked to a certain extent by the fact that ccl has a listener autorelease pool. So if you do (in the ccl listener):

(#/allFrameworks ns:ns-bundle)

you won't get a console warning.

If you do:

(objc:invoke "NSBundle" "allFrameworks")

in a LispWorks listener, you'll get a console warning:

8/27/10 11:34:58 AM	lispworks-6-0-0-macos64-universal[8632]	*** __NSAutoreleaseNoPool(): Object 0x11514ae60 of class NSCFArray autoreleased with no pool in place - just leaking

because LispWorks does not have the equivalent of ccl's ccl::*listener-autorelease-pool*.

If you want an object returned from a convenience method to still be live when leaving the relevant scope (i.e., when the pool is drained) you need to both have a pool in place *and* retain the object. The pool ensures that the implicit autorelease is balanced, and the retain increments the ref-count so that the object is still live when the pool's scope is exited.

In the function I wrote, I don't want the ns-array to still be around when the function returns (i'm converting the strings to lisp strings and returning lisp strings only, not ns-objects). So I just have a pool in place, and the ns-array is automatically released when the function returns.

warmest regards,


Raffael Cavallaro
raffaelcavallaro at me.com

More information about the Openmcl-devel mailing list