views:

286

answers:

3

Hi,

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!

+3  A: 

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.

e.James
The problem is that if you don't do the "someObject = nil;" part, which you are unlikely to do when you are not intentionally trying to create leaks, then Instruments often doesn't find them.
Kristopher Johnson
+1  A: 

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.

+1  A: 

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.

Kendall Helmstetter Gelner