Invisible memory leaks... iOS 4

89 Views Asked by At

So I've got an issue with memory. It seems that I am not properly releasing or deallocating objects because I am getting this subtle buildup of memory in my game.

I init all objects like this:

self = [super init];
if (self != nil) {
    //inititalize object
}

I release all objects in the dealloc methods like so:

[object release], object = nil;

Now I feel I should mention that my game runs on views. I have the main view that loads the sub-views into one variable called 'currentView'. I switch between the views like so.

if (currentView != nil) {
    [currentView dealloc];
}
currentView = [[newView alloc] initWithVariables:vars];

I want to know if the issue is with my initialization and deallocation of objects or if its the views. I also want to know any strategies I can use to track down any leaks that don't show up in instruments.

I need this information ASAP, and if you can help it would be REALLY appreciated. Thanks.

EDIT: When I run it through instruments it shows the memory my app uses. and it has a strange pattern. When it loads the first view it starts with approx. 17mb used. Then I switch to the second view and it goes up to 22mb. Now if I go back to the first view it DOESN'T go down to 17mb again but down to about 20mb instead. Now when I continue to switch between the two it goes between 22mb and 20mb and stays pretty much the same. How can this be explained?

EDIT2: The pattern explained in the above edit is consistent throughout the entire game. Because of this consistency I've noticed a 70kb per-level leak in my game. Obviously this should not cause any problems while my game stays under 100mb so unless they play my game for EXTENDED periods of time, this shouldn't be a problem.

Although, I would still like to know how I can track down that 70kb leak.

1

There are 1 best solutions below

3
On

You should be using release instead of dealloc. Every call to alloc should be matched with a release or autorelease; in your case, release because you want to control when it's freed.