1

When things were really difficult, and I wanted to see why my retain count was so high, I'd just override retain/release and call super, set a breakpoint, and visually look at what is retaining my objects.

I ran into a situation where this would drastically help, but I must bridge and turn off ARC to do this.

Has anyone found any way to do this in pure Swift? I remember not being able to override the functions within the Swift manual.

Thank you

Stephen J
  • 2,367
  • 2
  • 25
  • 31
  • [When to use -retainCount?](http://whentouseretaincount.com) – zaph Aug 21 '15 at 17:57
  • That's funny. You haven't had to debug animations with custom view stacks on top of blocks in people's code you haven't written before? I overrode retain and solved a memory leak in minutes by learning the other coder didn't use blocks with weak. It's my "last resort", and yes, worst way to find bugs, but it is 100% accurate, unlike recalling all the manuals, points of retain, and manually searching. But yes, that is good advice, in general, but not for obfuscated code, even if easily readable, through race conditions, animations, cycles... blah blah blah. Good point in general Z – Stephen J Aug 21 '15 at 18:04

1 Answers1

3

If you need to see where retains, releases and autoreleases occur for an object use instruments:

Run in instruments, in Allocations set "Record reference counts" on on (you have to stop recording to set the option). Cause the problem code to run, stop recording, search for there ivar of interest, drill down and you will be able to see where all retains, releases and autoreleases occurred.

enter image description here

zaph
  • 111,848
  • 21
  • 189
  • 228