tags:

views:

299

answers:

1

So here's my setup:

  • User spins PickerWheel, chooses which section of the app to navigate to.
  • The app loads a UIViewController from a XIB file and pushes it on to the navigationController stack
  • User can pop back at anytime and choose another section to navigate to - the viewController is (supposed to be) completely destroyed and re-allocated for the new XIB file

It seems simple, but each of these sections is very resource intensive. I can't find a good way to completely clear the XIB out of memory when they pop back - I try just calling [viewController release], and while it works and ends up calling the -(void)dealloc method of the UIViewController subclass, some of the contents from the XIB file still stay in memory (I can see them there in ObjectAllocations, and I can see a lot of memory left over in ActivityMonitor).

Basically what I am asking is what is the best way to completely remove a dynamically-loaded XIB from memory?

+3  A: 
viewController.view = nil;

If view is nil on a NIB-controlled UIViewController, then it will automatically reload the NIB the next time it's requested. This is exactly how -didReceiveMemoryWarning works.

As I think about this more, this won't immediately drop your IBOutlets, which in your case probably matters. So you need to also implement the special memory management for IBOutlets described in Memory Management of Nib Objects.

You need to implement -setView: as described. Read this entire document carefully. I've written up a quick summary of the key points in Memory Managing IBOutlets.

Rob Napier
Wow. Three words cancels out three hours of work :P You, sir, are a champion. Much appreciated.
This is perhaps one of the most important posts on StackOverFlow - iPhone. Rob Napier is my MVP. If you're doing anything that requires complex Navigation and UIViewControllers, please, please, please pay attention to this post! Thanks Rob!
Jordan