今天我做了一些测试,我很好奇的结果。我做了一个应用程序(ARC),它有UINavigationController和两个UIViewControllers。在第一个视图中有一个按钮,当按下该按钮时,将加载第二个视图。在第二个视图中,当检测到摇晃手势时,加载第一个视图,依此类推。我在文书中注意到,每次加载视图时,堆都会增长。下面是一些代码堆内存越来越大
AppDelegate.m
self.navigationController = [[UINavigationController alloc]init];
self.window setRootViewController:self.navigationController];
FirstViewController *firstview = [FirstViewController alloc]init];
[self.navigationController pushViewController:FirstViewController animated:YES];
FirstViewController.m
-(IBAction)loadSecondView
{
SecondViewController *secondview = [SecondViewController alloc]init];
[self.navigationController pushViewController:secondview animated:YES];
}
SecondViewController.m
-(IBAction)loadFirstView
{
FirstViewController *firstview = [FirstViewController alloc]init];
[self.navigationController pushViewController:first view animated:YES];
}
我想不通,为什么出现这种情况。在这种情况下如何避免堆积如山?
在你的第二个的viewController有将已经后退按钮,当你点击就可以了,所以没必要实施loadFirstView method.because每次你被creatng FirstViewController的新实例时自动工作,这就是为什么内存堆中成长每次。 – 2012-02-10 08:55:57
我不想那个按钮。我想在检测到摇晃手势时工作。 – objlv 2012-02-10 08:58:43
摇:[self.navigationController popViewControllerAnimated:YES]; – NeverBe 2012-02-10 09:09:38