Understanding the Instrument for memory leak checking - iPhone

前端 未结 5 1450
无人共我
无人共我 2021-02-03 14:57

\"alt

Above given images is of my application leaks.

Here I want to understand that, in Extended Det

5条回答
  •  北荒
    北荒 (楼主)
    2021-02-03 15:06

    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.

提交回复
热议问题