0

I have a memory issue in my app and it is hard to reproduce. I added Malloc Scribble, and Guard Malloc in my scheme and now I have a list of leaked objects. Unfortunately this are not objects I created.

enter image description here

How can I debug this and find the cause of my leaks? Maybe you can recommend a good tutorial. I could create a UI-Tests that opens and closes the problematic UI again and again and sometimes it crashes. Fixing this leakes might be a good point to start but I do not know how to find the error in my code.

netshark1000
  • 7,245
  • 9
  • 59
  • 116
  • 1
    I always start with “[debug memory graph](https://stackoverflow.com/questions/30992338/how-to-debug-memory-leaks-when-leaks-instrument-does-not-show-them/30993476#30993476)”, and only when that fails do I turn to Allocations and Leaks tools in Instruments. And I find that the “malloc stack” feature is useful in conjunction with “debug memory graph”. – Rob Aug 07 '19 at 14:49
  • We don’t have enough here to diagnose, but the presence of the `_NSCFTimer` would make me double check my code for any `Timer` instances (esp repeating timers), if any. And the Realm references would make me want to double check any Realm closures I had, if any. – Rob Aug 07 '19 at 14:52
  • so what would you check there? Strong references? – netshark1000 Aug 08 '19 at 05:37
  • You look for objects there that should not be there. In the obvious cases, you’ll see instances of your own objects listed which shouldn’t be there (e.g. you’ve dismissed the “second view controller” but still see it listed there in memory). Once you find something like that, you then can see what is keeping a strong reference to it. Sometimes it will be something like a sloppily implemented repeating timer. Sometimes it will be a typical strong reference cycle (e.g. a delegate that was implemented as strong reference rather than weak reference). – Rob Aug 08 '19 at 15:01

0 Answers0