nonamelive
nonamelive

Reputation: 6510

iPad View Controller Memory Management

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. :)

Upvotes: 0

Views: 455

Answers (3)

elp
elp

Reputation: 8131

Have you checked your memory leaks?
Instruments -> Leaks.

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

Another consideration is to alloc and release all object correctly, that is not easy, but necessary.

You can enable another control from build options: RUN_CLANG_STATIC_ANALYZER to show all wrong release at compile time.

alberto,

Upvotes: 0

Di Wu
Di Wu

Reputation: 6448

My suggestion is that you take a look at each of your view controllers' viewDidUnload method. From iOS 3.0 on, this is the place iOS will try to get some memory back when your app receives a memory warning.

To be more clear, you should try to set all your IBOutlets to nil in this method so that when called, your unnecessary UI stuff (unnecessary because at that time those nib files are not shown to the user) will be cleared and return their allocated memory to the OS. And when they show up again they'll be recreated by the viewDidLoad method.

Sample code:

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;

Upvotes: 0

BastiBen
BastiBen

Reputation: 19870

The iPad only has 256 MB of RAM, which is half of what the iPhone 4 has.

It seems that your view controllers are loading a lot of resources or are allocating a lot of memory somewhere else. You should be able to find out where exactly the memory is allocated with the Instruments tool.

Upvotes: 1

Related Questions