简体   繁体   English

调用popViewController时未释放内存

[英]Memory not released when popViewController Called

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. 问题是内存第一次增加了5mb(在Activity Monitor上)。当我弹出控制器时,它没有被释放。 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]; UIView * myView = [UIView alloc] init];

self.vi=myView; self.vi = myView;

[myView release]; [myView版本];

UIScrollView *mySv=[UIScrollView alloc]init]; UIScrollView * mySv = [UIScrollView alloc] init];

self.sv=mySv; self.sv = mySv;

[mySvrelease]; [mySvrelease];

UIProgressView*myPv=[UIProgressViewalloc]init]; UIProgressView * myPv = [UIProgressViewalloc] init];

self.pv=myPv; self.pv = myPv;

[myPvrelease]; [myPvrelease];

UIWebView *myWv=[UIWebView alloc]init]; UIWebView * myWv = [UIWebView alloc] init];

self.wv=myWv; self.wv = myWv;

[myWv release]; [myWv发布];

-(void)dealloc { [wv relase]; -(void)dealloc {[wv relase];

[sv release] [sv版本]

[pv release]; [pv版本];

[vi release]; [vi版本];

[super dealloc]; [super dealloc];

} }

wv,sv,pv,vi are MyViewControoler variables which have retain attribute. wv,sv,pv,vi是具有保留属性的MyViewControoler变量。 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. 我已经通过在其MyController类上验证没有对象泄漏到MyController类中。

MyViewController的内容会泄漏

Its not a memory leak. 它不是内存泄漏。 iOS cache the controllers you have visited recently. iOS会缓存您最近访问过的控制器。 It will get deallocated by iOS itself when your application needs memory to execute some other tasks. 当您的应用程序需要内存来执行其他一些任务时,它将由iOS自身释放。

try this method in MyViewController.m file 在MyViewController.m文件中尝试此方法

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS popViewController不会释放内存并且未调用dealloc - iOS popViewController does not free memory and dealloc not called NSTimer:释放时会调用invalidate吗? - NSTimer: is invalidate called when it is released? PopViewController占用内存 - PopViewController is holding up memory 弹出时未从内存中释放UIViewController - UIViewController not being released from memory when popped 释放类对象时使用块进行内存管理 - Memory management with blocks when class object is released 为什么 ARC 在 popViewController 之后不释放内存 - Why ARC is not deallocating memory after popViewController iOS7崩溃 - 在View ViewController上调用PopViewController - iOS7 Crash - PopViewController called on a Landscape ViewController 应该从父 ViewController 还是子 ViewController 调用 popViewController? - Should popViewController be called from the parent or child ViewController? 拖动并释放通知后,将在iOS中调用ApplicationBecomeActive - When notification is dragged and released, ApplicationBecomeActive gets called in iOS 与UITapGestureRecognizer结合使用时,UIScrollView子视图已释放(删除)内存 - UIScrollView subview is memory released (removed) when it's used in conjunction with UITapGestureRecognizer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM