How to exactly find where memory is leaking in project of iPhone

懵懂的女人 提交于 2019-11-29 01:49:13

问题


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?


回答1:


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.

You'll get something like this.




回答2:


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.



来源:https://stackoverflow.com/questions/10493470/how-to-exactly-find-where-memory-is-leaking-in-project-of-iphone

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