1

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.

iAviator
  • 1,310
  • 13
  • 31

3 Answers3

1

MyViewController have a content which does a leaks

NeverBe
  • 5,213
  • 2
  • 25
  • 39
0

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.

Apurv
  • 17,116
  • 8
  • 51
  • 67
-1

try this method in MyViewController.m file

- (void)dealloc
{
    //release any object thats retained into the memory
    [super dealloc];
}
hchouhan02
  • 948
  • 1
  • 8
  • 18