[Openmcl-devel] Allocating temporary nsstrings

Raffael Cavallaro raffaelcavallaro at mac.com
Sun Mar 13 22:30:25 UTC 2011


On Mar 13, 2011, at 4:31 PM, Ron Garret wrote:

> Empirically it seems they are allocated in the current thread's autorelease pool.  So they go away when the current thread terminates.

Yup; autorelease pools are nested/stacked per thread:

"Autorelease pools are arranged in a stack, although they are commonly referred to as being “nested.” When you create a new autorelease pool, it is added to the top of the stack. When pools are deallocated, they are removed from the stack. When an object is sent an autorelease message, it is added to the current topmost pool for the current thread."

from:

<http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAutoreleasePools.html>

But:

"If you are making Cocoa calls outside of the Application Kit's main thread, however, you need to create your own autorelease pool."

So every call to process-run-function that generates autoreleased objective-c objects should use ccl::with-autorelease-pool or these autoreleased objects will just leak memory; IOW, process-run-function does not set up an autorelease pool for you - you need to do it yourself.

warmest regards,

Ralph




Raffael Cavallaro
raffaelcavallaro at me.com








More information about the Openmcl-devel mailing list