views:

34

answers:

1

Hi, I'm using a TabBarController with a few Tabs and I have memory problems when switching through the tabs and the contents. Is there a way to release and dealloc everything when I go to another ViewController ?

So when I am in Tab#1 with ViewController #1 and I go to Tab#2 with ViewController #2, how can I free all the memory ViewController #1 took ?

Thx ! Sebastian

A: 

The tab bar controller retains all its view controllers so unless you remove the corresponding tab from the tab bar, you cannot free all the memory the view controller takes. However, a view controller should usually not require a lot of memory except for its view. Make sure you release all your outlets (and everything else that can be recreated in viewDidLoad) in viewDidUnload. If your view controller holds significant other amounts of data, you should release them in didReceiveMemoryWarning if you can recreate them later.

Ole Begemann
Thx :) One more question ... in my viewDidLoad of my ViewController I'm building a UIScrollview with: myScroller = [[UIScrollView alloc] initWithFrame:CGRectMake ... and I'm adding many subViews to the myScroller. What is the best way to release the whole scroller with its subviews ? And where should I do it ? And when I release it, I have to rebuild it in the viewWillAppear so it is rebuilt when the user comes back to the tab, is that correct ?
Sebastian
You should read up on the relationship between `viewDidLoad` and `viewDidUnload`. Everything you create in `viewDidLoad` and all NIB outlets you are retaining, you must release in `viewDidUnload`. `viewWillAppear:` has nothing to do with it. You certainly don't have to recreate your views in that method because `viewDidLoad` will be called whenever needed.
Ole Begemann