Re: ARC Retain Cycles
Re: ARC Retain Cycles
- Subject: Re: ARC Retain Cycles
- From: Cody Garvin <email@hidden>
- Date: Sun, 20 Apr 2014 11:58:48 -0700
Hi Dave!
First, check to make sure zombies are disabled. I made the mistake of trying to track down leaks via instruments, and totally forgot they were enabled: wild goose chase.
Second, while using instruments use the “mark heap” tool. Get your app up and running. Mark the heap. Then start your image downloads, while that is transpiring, mark the heap again. This will help narrow down the code that could possibly be causing this.
Third, keep in mind that blocks keep strong references to self (especially callbacks). I’d look for any self reference inside blocks, weakify, then strongify in the block if necessary.
__weak typeof(self) weakSelf = self;
void (^someWeirdBlock)(void) =
^{
typeof(self) strongSelf = weakSelf; // Helps keep a reference around, but doesn’t hold onto forever
};
Hope this helps
- Cody
On Apr 20, 2014, at 11:52 AM, Dave <email@hidden> wrote:
> Hi,
>
> I have a inheriated an Application that I converted to use ARC. When I run it now, I see that memory is being allocated and not released. At least, when I run the App with the debugger view active, I see the memory growing and growing when I do some intensive Image Downloads as a test for the network layer (I’ve not run it under the Profiler yet).
>
> Since this is ARC, I’m guessing that the Leak is caused by some kind of retain cycle that is holding onto the image data after the network layer is finished with it.
>
> My question is, what is the best/easiest way to detect these issues under ARC? I’ve had quite a lot of experience doing this with non-ARC projects, but never had this problem before using ARC. Under non-arc, if push came to shove, I’d override retain/release etc. and add logging which usually showed up the problem quickly. Of course I can’t do that anymore now I’ve converted it to ARC.
>
> The Network Layer has a lot of prooperties that have the retain attribute (I’ve not changed them to strong), I’m sure it’s something to do with either a retain cycle, but there’s so much code it’s hard to see the wood from the trees.
>
> Thanks in advance for any suggestions or help.
>
> All the Best
> Dave
>
>
> _______________________________________________
>
> 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
_______________________________________________
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