1
votes

Below is the code in which i have some doubts:-

MyController *vc= [MyViewController alloc] initWithNibName:@"myController"
                                                    bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
[vc release];

Then, i pop my controller by pressing the back button on nav bar.

The problem is memory is increased by 5mb(On Activity Monitor) for the first time.And when i pop the controller it doesnt get released. And when i do the push and pop again and again the memory increases by small amount and decreased too.

UIView *myView=[UIView alloc]init];

self.vi=myView;

[myView release];

UIScrollView *mySv=[UIScrollView alloc]init];

self.sv=mySv;

[mySvrelease];

UIProgressView*myPv=[UIProgressViewalloc]init];

self.pv=myPv;

[myPvrelease];

UIWebView *myWv=[UIWebView alloc]init];

self.wv=myWv;

[myWv release];

-(void)dealloc { [wv relase];

[sv release]

[pv release];

[vi release];

[super dealloc];

}

wv,sv,pv,vi are MyViewControoler variables which have retain attribute. I wrote this code to check the memory management concepts,but iam confused now seeing the activity monitor and instruments results.

I have verified that no object is getting leaked in my MyController class by using Instruments on it.

3

3 Answers

1
votes

MyViewController have a content which does a leaks

0
votes

Its not a memory leak. iOS cache the controllers you have visited recently. It will get deallocated by iOS itself when your application needs memory to execute some other tasks.

-1
votes

try this method in MyViewController.m file

- (void)dealloc
{
    //release any object thats retained into the memory
    [super dealloc];
}