Re: ARC Retain Cycles
Re: ARC Retain Cycles
- Subject: Re: ARC Retain Cycles
- From: Jim McGowan <email@hidden>
- Date: Sat, 26 Apr 2014 15:27:40 +0800
On 25 April, 2014 5:45:24 pm HKT, Dave <email@hidden> wrote:
> It’s not dogma! autorealease meant my App peaked at 150MB, whereas it needed 10 MB! Autorelease caused 140 MB of data to be useless held in memory for the duration of the Thread for no good reason.
>
‘Autorelease’ wasn’t causing your app to use 150mb, it was your loop that was causing the memory usage. If you have a loop where each iteration is going to create/fetch/copy a significant amount of data, then it is pretty standard practice to have an autorelease pool inside the loop, as otherwise you are depending on the next pool in the chain, which is probably the main thread’s pool which is only popped once per event loop interation.
> You can’t avoid autorelease, you need to do some work to undo it ASAP to stop the memory building up too much. In this case the solution is to copy the data into new objects and then drain the pool. Works a treat - you can’t avoid it BUT you can undo it!
I don’t really understand what you mean by “undo it”, but I the thing to remember is that autorelease pools are not like garbage collection, you have to be responsible for them in your own code in the same way that you are responsible for balancing new/init/copy/retain with release.
Jim
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden