【发布时间】:2011-07-23 20:58:05
【问题描述】:
我的 iPhone 应用程序出现内存问题,我不知道发生了什么。
所以,我观察到应用程序的内存使用量在从一个 UIViewController 转到另一个时不断上升。我使用了“Allocations”工具中的“Mark Heap”工具,它表明唯一没有被释放的对象是我的 UIViewControllers。
更具体地说,我让我的两个 UIViewControllers。第一个名为 PuzzleViewController,第二个名为 Options。当应用程序启动时,会出现 PuzzleViewController。我在此处标记一个堆以设置基线,然后按“选项”按钮,该按钮将显示选项 UIViewController。我回到第一个并再次标记一个堆。在一遍又一遍地重复这些步骤之后(比如 20 次左右 :D),我观察到在每次 Heapshot 之后我有大约 22 个对象还活着。其中两个对象是我的 UIViewControllers 的实例。
我真的不知道发生了什么。
这是我切换到选项 UIViewController 的方式:
- (IBAction) onOptionsButton: (id) sender
{
Options *viewController = [[Options alloc] init];
[self presentModalViewController:viewController animated:YES];
[viewController release];
}
这是我返回 PuzzleViewController 的方法:
- (IBAction) onMainMenu:(id) sender
{
PuzzleViewController *modalView = [[PuzzleViewController alloc] init];
[self presentModalViewController:modalView animated:YES];
[modalView release];
}
我的 viewDidUnload 函数被正确调用,但从未调用任何 dealloc 函数。
谢谢你, 安德烈
【问题讨论】:
-
你是如何关闭选项视图控制器的?
-
@Firoze Lafeer,我真的不知道......对不起,我是 iPhone 编程的新手。我应该怎么做,有什么用?非常感谢!
-
那么,您的用户如何返回 PuzzleViewController?什么按钮和代码可以做到这一点?
-
@Firoze Lafeer,我已经发布了问题的代码。
-
这可以正常工作。如果层次结构更深,您可能会考虑使用 UINavigationController(或多个)
标签: iphone objective-c memory-management uiviewcontroller dealloc