如何彻底删除UIViewController? [英] How to delete UIViewController corectly?

查看:45
本文介绍了如何彻底删除UIViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MyPlatesViewController* viewController = [[MyPlatesViewController alloc] initWithNibName:@"MyPlates" bundle:nil ];
[self.view addSubview:viewController.view];

然后我删除我的viewController

then i delete my viewController

[self.view removeFromSuperview];

但泄漏仪显示20 MB内存

but leak instrument shows 20 MB memory

怎么了?

推荐答案

您泄漏了视图控制器对象.从其超级视图中删除该视图后,还需要释放该控制器.

You leaked the view controller object. After you remove the view from its superview, you need to release the controller as well.

或者,您可以执行以下操作:

Alternatively, you can do the following:

[self presentModalViewController:viewController animated:NO];
[viewController release];

然后,当调用 dismissModalViewController 时,视图和视图控制器将被正确释放.

Then, when dismissModalViewController is called, both the view and the view controller will be released properly.

这篇关于如何彻底删除UIViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆