Help finding memory leaks (general tips)

余生颓废 提交于 2019-12-04 13:18:12

This is how I would approach it,

  1. Name all you classes with a prefix so you can easily see them in Instruments

  2. XCode->Run->Run with performance tool->allocations

Now stop your app and type the name of class you suspect is leaking in the search box. (this is where the prefix is handy). The start instruments again with the "Record" button

  1. The living column should go up and down as you allocate objects. Note if it doesn't go down you have a leak.

It is always not necessary that you have leaks in the case you have mentioned. You might have used lot of autoreleased objects in the point of execution time that you mention here. You might be adding a heavily sized objects to a collection object. If that is the case, use a separate Autorelease pool for that case, reduce the memory footprint of the application.

It's preferred if you can make use tools to find leaks, but if are completely stumped, there is another technique that I use.

Start with commenting out almost everything and then slowly add back one component at a time until the memory leak occurs again. That way you can zero in on the function or block of code that is creating the problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!