0

I have 3 view controllers in my iPad app. When the first one shown up, the Activity Monitor in Instruments told me that the app's memory was 25MB. After a [self presentModalViewController] call, a new view controller popped up, the memory gone up to 50MB, and then the third one, 70-75MB.

What is the best view controller memory management for the iPad development? I always receive Memory Warning now when I'm on a real iPad.

Thanks in advance. I'm sorry for my English, since it's not my native language. :)

4

3 回答 3

1

iPad 只有 256 MB 的 RAM,是 iPhone 4 的一半。

您的视图控制器似乎正在加载大量资源或在其他地方分配大量内存。您应该能够使用 Instruments 工具找出内存的确切分配位置。

于 2010-12-19T14:14:15.113 回答
0

我的建议是您查看每个视图控制器的 viewDidUnload 方法。从 iOS 3.0 开始,当您的应用收到内存警告时,iOS 将尝试在此处取回一些内存。

更清楚地说,您应该尝试在此方法中将所有 IBOutlets 设置为 nil,以便在调用时,您不必要的 UI 内容(不必要,因为当时那些 nib 文件未向用户显示)并返回它们分配的内存到操作系统。当它们再次出现时,它们将由 viewDidLoad 方法重新创建。

示例代码:

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
于 2010-12-19T15:09:22.560 回答
0

你检查过你的内存泄漏吗?
仪器 -> 泄漏。

http://developer.apple.com/library/ios/#documentation/Performance/Conceptual/ManagingMemory/Articles/FindingLeaks.html

另一个考虑是正确分配和释放所有对象,这并不容易,但必要。

您可以从构建选项启用另一个控件:RUN_CLANG_STATIC_ANALYZER在编译时显示所有错误的版本。

阿尔贝托,

于 2010-12-19T15:15:45.977 回答