2

While debugging my App with Instruments I found a couple of memory leaks. I haven't done this since MRC, so forgive me if I'm missed anything obvious.

Going to the Cycles and Roots Section on the 'Leaks' instrument revealed many 'Root Leaks'.
The call tree is empty. All the leaks say "Malloc X Bytes [no ivar] Malloc X Bytes" and nothing more. (There's a graph on the right showing this too)

How would I go about finding the cause for these memory leaks? I haven't written all the code so It's difficult for me to find the exact code that causes this.

Since they come up under 'Cycles and Roots', does this have anything to do with retain cycles? Could they be a consequence of not nulling out blocks correctly?

I'm Using ARC, Xcode 4.6.3, Instruments 4.6 and the iOS 6.1 Simulator

SEG
  • 1,717
  • 1
  • 18
  • 33
  • See the call tree, it will show you the callstack. – doptimusprime Dec 10 '13 at 04:56
  • "The call tree is empty". – SEG Dec 10 '13 at 04:57
  • 1
    Retain cycles are not caused by blocks, they are causes by one-to-one strong ownership between two objects, or by a construct that indirectly retains an object that is in turn retained by the caller. What you're seeing in that section of instruments are indeed retain cycles in your code, but nil'ing out your blocks will not actually free any objects captured by them, nor will it break the cycle. – CodaFi Dec 10 '13 at 05:26
  • Thanks CodaFi. So, just to confirm, `self.completionHandler();` appended by `self.completionHandler = nil;` will not break the cycles? If so, have you got some advice on how I'm supposed to fix this? – SEG Dec 10 '13 at 05:35
  • 2
    There's a couple ways to fix this depending on what exactly is causing the cycle. For simple strong-strong relationships, turning one side weak fixes it. For block retain cycles, the [WeakSelf-StrongSelf](http://stackoverflow.com/a/17105204/945847) dance works best. – CodaFi Dec 10 '13 at 06:12

0 Answers0