简体   繁体   中英

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

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!

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM