Search code examples
iphoneobjective-cmemory-leaksautomatic-ref-countinginstruments

Instruments Memory Leak With ARC Confusion


Good morning,

I was doing some fine tuning on this application I've been working on, just to make sure everything was running smooth and no memory leaks happened. So I ran my app with Instruments and I selected the allocations and leaks tool.

My app ran perfectly fine until Insturments detected a leaked object which happened to be a UIImage. What confused me was that I was using ARC so my understanding was that all retain/release/autorelease calls were being taken care of for me.

The other thing that confused me was, when I saw the Extended Details of the leak it showed that the Responsible Frame was [UIImage imageWithCGImage:scale:orientation] and I never called that method in my entire application, and I even did a search for it in my Workspace and got no results.

When I double clicked the leaked object to open it up in Xcode for me, it just opened up a frame and said "Unavailable". Screenshot below:

Instruments screenshot

And clicking on the Xcode logo to the right of it didn't help at all either. I've been trying to debug what this could possibly be and it has me stumped. I made sure NSZombieEnabled was set to YES just in case I tried to use a deallocated object, but I can't come to a solution. Why is this happening ( under ARC), and how can I fix it?

Thanks,

EDIT: This is the latest snapshot I have of the leak This is the latest snapshot that I have for the leak


Solution

  • Well, the leak is then probably originating somewhere from inside the framework (UIKit or deeper). If so, then there's not much you can do about it. Either it's some sort of "side effect" from inside your application that shows up later and deep inside UIKit ([UIImage imageWithCGImage:scale:orientation]), or it's some problem with UIKit itself. But in the end it's hard to tell for sure!

    Using ARC still doesn't guarantee 100% memory-leak free code! ;)