Iphone – Understanding the Instrument for memory leak checking – iPhone

instrumentsiphonememory-leaks

alt text

Above given images is of my application leaks.

Here I want to understand that, in Extended Detail – you can see different colors like light green, light pink, light brown, light purple.

What does each color indicates?

Now the other confusion is "How to locate the code which is creating a memory leak?"

Upto what limit of memory leak – the actual iPhone can go on with.
(suppose 10 bytes no problem, 20 bytes no problem & 200 bytes a problem)

  • What does each color indicates?
  • Which color indicates our code / From which detail we can get to the code where we have allocated the object & forgot to dealloc it?

(For example – On clicking of UIKit second cell in detail – we cant get to the code)

  • Why we must resolve all the leaks? – even a single leak can chock up iPhone ?
  • Why iPhone allows leaks to be remain in memory? / why garbage collection isn't done automatically after termination of application?
  • If I try to dealloc objects which should be deallocated according to instruments, My application terminates abnormally. If I don't dealloc, My application runs perfectly, How?
  • Why it is suggested that you wait in a view up to 10 or more seconds, if there is a leak, leak will be detected by Instruments?

Best Answer

Ignore the colors, in that one the [DashBoard viewDidLoad] is the source of the leak, something in how it's initializing a URLConnection (possibly you did not free that when the connection was finished?)

Now to answer the other questions you had:

  • Why we must resolve all the leaks? - even a single leak can chock up iPhone ?

Yes. Part of the reason is not only that you will simply run out of memory, but since there is only so much memory to go around for the whole phone a watchdog application is constantly monitoring your app and will shut it down early if it sees memory use only ever growing...

  • Why iPhone allows leaks to be remain in memory? / why garbage collection isn't done automatically after termination of application?

All your application memory is freed when the app quits.

  • If I try to dealloc objects which should be deallocated according to instruments, My application terminates abnormally. If I don't dealloc, My application runs perfectly, How?

Here I can't help, you really need to read more on the retain/release memory cycle... if you release an object that has a retain count of 0, the app crashes because the object is gone.

  • Why it is suggested that you wait in a view up to 10 or more seconds, if there is a leak, leak will be detected by Instruments?

Because instruments works by sampling memory every so often, so it might take a little bit for instruments to get around to reading the memory after an action.

Related Topic