How do you detect memory leaks on iPhone?

2019-01-16 06:34发布

I'm using the Leaks Instruments feature through Xcode to (try and) find memory leaks. I still haven't figured out how to use this program. I click Leaks in the program and see memory increasing as I do various things in the simulator. I have Extended Detail pane displayed. The only thing in Extended Detail pane that references my app is main. As in the main method produced by Xcode. Everything else is UIKit, Foundations, and other SDK classes I didn't write. What am I doing wrong that nothing is showing up from my app?

Before I hit 3 minutes, there are over 100 leaks totaling 2.5k. Is this common?

12条回答
Root(大扎)
2楼-- · 2019-01-16 07:12
Run -> Start with Performance Tool -> Leaks
查看更多
叛逆
3楼-- · 2019-01-16 07:13

Keep in mind that the Simulator may leak when the device will not. Ran into that once already with UITableViewController class.

查看更多
Fickle 薄情
4楼-- · 2019-01-16 07:15

Leaks application that can be found in Xcode: run -> Start with Performance Tool -> Leaks.

Apple’s Instruments utility that can be found in /Developer/Applications/Performance Tools.

查看更多
太酷不给撩
6楼-- · 2019-01-16 07:24

Change the view to "Extended Detail" on the instruments panel. This will show you the stack trace of each leaked object after you stop recording and select the leaked object.

You do see calls into the API, but what you are interested in is finding the last method of your application before the API calls, that is where the leak is.

A tip: turn on "gather memory contents" in the leaks view. Seeing the object values should also help finding where the problem is.

You don't want any leaks. 100 leaks is not typical (at least in my apps ;) Typical should be 0.

查看更多
该账号已被封号
7楼-- · 2019-01-16 07:25

I've written up a Tutorial on using Instruments to track iPhone memory leaks. I'm not sure if it will help you with what you're dealing with or not...couldn't hurt, though. :-)

http://www.streamingcolour.com/blog/tutorials/tracking-iphone-memory-leaks/

查看更多
登录 后发表回答