Memory not released when popViewController Called

亡梦爱人 提交于 2020-01-23 17:37:08

问题


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.


回答1:


MyViewController have a content which does a leaks




回答2:


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.




回答3:


try this method in MyViewController.m file

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


来源:https://stackoverflow.com/questions/9226023/memory-not-released-when-popviewcontroller-called

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!