I have a game loop which I’ve put inside another loop like this:
for (int i = 1; i <= 10000; i++)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Game *game = [[Game alloc] init];
while ([game isActive])
[game nextRound];
[game release];
[pool release];
}
But I noticed in activity monitor that the real memory used grows indefinitely, and the app eventually crashes when it reaches around 1GB of memory. Instruments didn’t report any leaks. The clang static analyzer didn’t report leaks either.
My questions are:
- Does instruments always find all memory leaks?
- Could there be another reason for this indefinite increase of memory?
edit:
As pointed out by @Phillips, the reason was the zombies flag! After turning it off, the memory footprint is as expected.
Instruments can also be used to look at memory allocation. Try looking at the number of live objects when your memory has grown to see what kind of things are still active.
It’s not necessarily a leak causing memory to grow. For example, if you have some object created during
nextRoundthat retains yourGameobject, then releasing it in the code you posted might not result in adealloc.