NSAutoreleasePool

 

It may be right that the @NSAutoreleasePool has a lot to discuss, but as of now I think the most valuable inputs for me are the following two:

1. When we use the AutoreleasePool?

If you are running a run-loop it should be managing an autorelease pool automatically for you; it should create a pool at the top of the loop and drain it at the end of each pass through the loop.

You only need to cycle one yourself if you have other stuff going on outside of the runloop.

http://stackoverflow.com/questions/3807035/best-way-to-periodically-drain-the-autorelease-pool-on-a-long-running-background

2. When is AutoreleasePool drained?

The Application Kit creates an autorelease pool on the main thread at the beginning of every cycle of the event loop, and drains it at the end, thereby releasing any autoreleased objects generated while processing an event.

http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/
NSAutoreleasePool_Class/Reference/Reference.html

3. Difference between “release” and “drain”?

In a reference-counted environment, releases and pops the receiver; in a garbage-collected environment, triggers garbage collection if the memory allocated since the last collection is greater than the current threshold.

If your system has a garbage Collection, then -drain send message (objc_collect_if_needed) for GC. If you haven’t GC, then drain = release

http://stackoverflow.com/questions/797419/whats-the-difference-between-sending-release-or-drain-to-an-autorelease-pool

Hope this helps!
Anindya

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s