Monday, October 26, 2009

iPhone Development Basics - Memory Management Part 4

So far we've seen 3 videos by Mark Johnson on iPhone memory management:
iPhone Development Basics - Memory Management Part 1
iPhone Development Basics - Memory Management Part 2
iPhone Development Basics - Memory Management Part 3
And we've been using these videos to understand iPhone application memory management and gain some insight has to why iPhone apps crash.  In today's video, Mark describes a memory management programming convention used by iPhone developers for managing objects - either they're in the Autorelease pool or they are not. It's a very technical video but worth listening to because Mark warns of things not to do otherwise an app will crash - something worth being curious about when talking to your dev team.

Suggested questions for Part 4:
(4:02min) Why does returning a reference to a deleted object cause a crash? Why would that happen?
(5:17min) What does it mean to "own" an object versus having it be part of an Autorelease pool?

1 comments:

Anonymous said...

A common memory leak problem I've noticed during iPhone app testing occurs when using UITabBarController and UINavigationController. Both of these controllers will retain view controllers that are pushed or added to their view. It is safe (and necessary to prevent memory leakage) to release view controllers after pushing or adding them to a UITabBarController or UINavigationController.

example:

myNavigationController = [[UINavigationController] alloc] init];
myCustomViewController *viewController = [[myCustomViewController alloc] init];
[navigationController pushViewController:viewController animated:NO];
[viewController release];

The navigation controller must also be released eventually. (usually in dealloc)

It is also safe to release a navigation controller after adding it to the view of a tab bar controller since the tab bar controller will retain it.

Post a Comment