Thread with lot of autoreleased objectIs is it mandatory to use autorelease pool on this scenario if yes/no why?

StackOverflow https://stackoverflow.com/questions/11488990

Question

Consider we are implementing our own thread with lot of autoreleased object. Is it mandatory to use autorelease pool on this scenario if yes/no why?

Was it helpful?

Solution

It's mandatory to have an autorelease pool on any thread that you create, because Cocoa internals expect there to be one in place and you will leak memory if it isn't there.

Cocoa always expects there to be an autorelease pool available. If a pool is not available, autoreleased objects do not get released and your application leaks memory. If you send an autorelease message when a pool is not available, Cocoa logs a suitable error message.


Applications that link in Objective-C frameworks typically must create at least one autorelease pool in each of their threads.

OTHER TIPS

It is mandatory even with a single autoreleased object, because otherwise it will leak.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top