我的 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 函数。
谢谢你,安德烈