(iPhone/iPad开发)解决viewController后退时不执行delloc()问题
2012-07-16 01:08
816 查看
刚调试程序时发现一个很诡异的问题,我从ViewController A push进 ViewController B,在从B back时发现程序不会执行B里面的delloc(),很诡异的问题,因为按理说此时点击back是执行pop操作的,是会执行delloc()函数的,但经调试发现确实没有执行。
后来经过google发现,
也就是说,我当前View B 内存中计数器不为0,经排查发现,我是在ViewDidLoad函数里面开启了一个time类型,
timer=[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
这一句调用的时候对 target:self 进行了retain,这时候你pop回上一级,self的引用计数还剩1,所以铁定不会dealloc,我的解决办法是在-
(void)viewWillDisappear:(BOOL)animated()函数里执行[timer invalidate];这样,self view计数器为0,当前view执行了delloc()。
后来经过google发现,
The dealloc method was not being called if any of the references held by a viewcontroller were still in memory. |
timer=[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
这一句调用的时候对 target:self 进行了retain,这时候你pop回上一级,self的引用计数还剩1,所以铁定不会dealloc,我的解决办法是在-
(void)viewWillDisappear:(BOOL)animated()函数里执行[timer invalidate];这样,self view计数器为0,当前view执行了delloc()。
相关文章推荐
- (iPhone/iPad开发)present某一个ViewController后,试图添加UINavigationController遇到的一些问题
- (iPhone/iPad开发)presentViewController相应方法在SDK5.0前后变化后通用方法
- ipad开发中UIPopoverController中显示自定义view尺寸显示问题
- iphone开发学习,开源之SVWebViewController,UIWebView支持后退、前进、刷新、使用Safari打开
- [安卓开发]关于WebView执行js 会输出的问题解决
- [转]浅论ViewController的加载 -- 解决 viewDidLoad 被提前加载的问题(pushViewController 前执行)
- iphone 开发过程中一些问题的解决方法(MPMoviePlayController)
- iOS开发Debug之UIAlertViewController在iPad弹出崩溃问题
- iOS:iPad和iPhone开发的异同(UIPopoverController、UISplitViewController)
- (iPhone/iPad开发)presentViewController相应方法在SDK5.0...
- viewController返回时不执行delloc方法问题
- iphone ipad viewController不响应横竖屏转换相关消息的问题
- (iPhone/iPad开发)present某一个ViewController
- 浅论ViewController的加载 -- 解决 viewDidLoad 被提前加载的问题(pushViewController 前执行)
- (iPhone/iPad开发)解决CAStreamBasicDescription在项目中无法编译通过问题
- iOS开发-自定义TabBar使用popToRootViewControllerAnimated重叠问题解决
- iphone 开发过程中一些问题的解决方法(UIWebView,UIActivityIndicatorView)
- iphone 开发过程中一些问题的解决方法(UIWebView,UIActivityIndicatorView)
- ipad开发中UIPopoverController中自定义view在Xcode6中尺寸匹配问题
- (iPhone/iPad开发)待解决问题