No leaks appearing in Instruments, even though I'm sure they exist

雨燕双飞 提交于 2019-12-24 05:14:05

问题


I'm checking for leaks in Instruments, and I've set to check every second, but no leaks are appearing.

I'm sure there must be some in my app, is there anything which could stop these from appearing? Is there a good way I can create a leak so that I can test if leaks do show up in Instruments?

Thanks!


回答1:


You're only going to find leaks with a tool if an object is allocated but no longer referenced. Another type of "leak" is to hold a reference to something that you didn't intend to. This typically happens with a collection like a hash table or a dictionary where key/value pairs get left in the collection that the programmer has forgotten about.




回答2:


Creating a leak is easy:

id someObject = [[NSObject alloc] init];
someObject = nil;

Drop some code like that into your app, and you should definitely see a leak show up in Instruments.




回答3:


I'm pretty sure as clemahieu postulated, what you are really seeing are over-retained objects - you think you have freed them but they still are being retained.

One quick sanity check for this is to set breakpoints in dealloc and see if the classes you expect to be freed really are.

You can also use the memory tracking Instrument (not leaks) to see what memory is still around - just make sure to select the "created and still living" option to check out just what what objects are still around.



来源:https://stackoverflow.com/questions/1056073/no-leaks-appearing-in-instruments-even-though-im-sure-they-exist

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