small medium large xlarge

27 Feb 2009, 21:53
Tony Eichelberger (8 posts)

I am not sure I am understanding the NSAutoReleasePool concept and so I tried to do something with the example to see what would happen.

I move the alloc of the pool outside of the while loop and then ran the code in Instruments. It ended up having memory leaks. The call to [pool drain] is still inside the loop, so why does it matter the scope that the pool was created in?

Moving the alloc of the pool back inside the while loop fixed the leaks.

So.. anyone up for explaining to me what is happening?


01 Mar 2009, 16:44
Bill Dudney (916 posts)

Hi Tony,

Sorry to be late getting back to you. According to the docs;

drain pops the autorelease pool so you don’t have one any more after calling drain.

Hope this helps.

06 Mar 2009, 21:02
Tony Eichelberger (8 posts)

Thanks, that makes sense. Calling drain on the autorelease pool actually deallocates it. I will have to get more familiar with where to find the documentation, too. :)

You must be logged in to comment