On Jan 26, 2011, at 1:23 PM, Tony Romano wrote:
I wanted to test for memory leaks using instruments. So I modified my code to explicitly not release the objects and proceeded to run Instruments/Leaks from Xcode. Instruments comes up, the tests run, but I am not seeing any leaks in instruments. Anyone have experience doing this that can share the proper technique for leak testing while running unit tests? I've used leaks successfully before in regular applications.
Leaks only detects leaks that are truly no longer reachable from an existing allocation. There can be many false positives; uncleared stack references, uncleared memory in the heap, etc.. that make it impossible for Leaks to detect the leak.
In any case, Leaks aren't really very interesting. Sure -- they are bad, but they are often a very small part of uncontrolled heap growth.
I'd suggest using Heapshot based analysis.
- run tests
- click Heapshot button
- run tests again
- click Heapshot button
... repeat a few more times ...
End result will be that each Heapshot iteration/generation will show you exactly how the heap is growing, regardless of whether the objects are truly leaked, you have a write-only cache, or some other growth causing behavior.
I wrote in detail about this here:
b.bum