7

While developing apps in Xcode memory leaks are occurring. When I checked them in extended detail view they are showing different methods that are not related to implemented. How to exactly find out which object is leaking and where it is leaking memory.

When ARC is enabled we have to take care of memory leaks or not?

Maksim
  • 2,054
  • 3
  • 17
  • 33
SURESH SANKE
  • 1,653
  • 17
  • 34

2 Answers2

11

Yes, even with ARC there are memory leaks. ARC is not a garbage collector, it only inserts for you, at compile time, retains, releases and autoreleases in key positions. So although it does help the developer, you should be aware that memory leaks still exist (for instance circular referencing). You can start by using the Static Analyzer and correct any problem it shows you. You can then go to Instruments and choose Leaks.

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
  • 5
    And, of course, you still have to manually manage memory for non-objective-c objects (C or C++). One more area is forgetting to invalidate repeating timers or other retained objects in a run loop (not an obvious leak). – borrrden May 08 '12 at 06:22
  • @JackyBoy: Can you tell me exactly where the memory leak is not handle by ARC with example. – Madan Mohan Feb 13 '14 at 11:08
  • @MadanMohan retain cycles for example. http://stackoverflow.com/questions/7761074/arc-blocks-and-retain-cycles – Rui Peres Feb 13 '14 at 11:46
11

Even with ARC memory leaks can occur, it just inserts release and autorelease during compile time.

1. You must check for leaks using Build and analyze in XCode, shift+command+b you should be clearing those issues.

2. After that you can start using the instruments by using profile option command+i . This will point you to where the leak might be.

This link will help you too http://soulwithmobiletechnology.blogspot.in/2011/04/how-to-check-memory-leaks-in-xcode-4.html

Edit: Added some screenshots to hopefully make it clear.

During profiling after selecting leaks choose the call tree option and check the boxes hide system libraries , invert call tree and show obj-c only as shown in image below.

After double clicking the symbol name below you'll get the line where it is leaking. enter image description here

You'll get something like this.

enter image description here

iNoob
  • 3,364
  • 2
  • 26
  • 33
  • 1
    Just a small point, it doesn't "show you where exactly the leaks are", you might be lucky and tell you, but normally it points where the leak **might** be. – Rui Peres May 08 '12 at 06:25
  • everything is ok..but when i saw the extended detail view the methods in that view are not matching any of the project methods – SURESH SANKE May 08 '12 at 07:28
  • @SAHARA, did you try going through the tutorial ? The red usually points to the leaking object. You can view that line in code by double clicking it. – iNoob May 08 '12 at 08:37
  • but when i double clicked it ...it is opening addresses instead of leaking line in project – SURESH SANKE May 08 '12 at 08:53
  • @SAHARA, please check my edit, hopefully it'll make things clearer. – iNoob May 08 '12 at 09:24
  • Yes in above first picture left side navigation window..when i click the "Show Obj-C Only" checkbox .then no leaks are appearing when i unchecked the checkbox then like above leaks are appearing..means they are not obj-c leaks or not – SURESH SANKE May 08 '12 at 09:47
  • Yes as far as i know they're not obj-c leaks. No idea how to guide you from here sorry. – iNoob May 08 '12 at 10:13