-dealloc correct, and -viewDidUnload will work, but usually saved views are filled only in -viewDidUnload and are not released. This seems to be the practice of Apple, and this is what they baked in Xcode when you create an automatically created IBOutlet through the Assistant editor.
For auto- -viewDidUnload IBOutlets, auto- -viewDidUnload as follows:
- (void)viewDidUnload { [self myView1:nil]; [self myView2:nil]; [self myView3:nil]; [super viewDidUnload]; }
Also, from Apple docs to -viewDidUnload :
The preferred way to give up ownership of any object (including retail outlets) is to use the appropriate access method to set the value of the object to nil. However, if you do not have an access method for this object, you may need to explicitly free the object
So you go. If your outlet has a property associated with it (which they should all have more), then zero in -viewDidUnload - but don't let go. This makes sense if you think what is actually happening in the synthesized accessory; the code looks something like this:
- (void) setMyView1 : (UIView *) view { if (myView1)
As you can see, setting the synhesize property to nil implicitly frees the saved object.
Also from the docs regarding -dealloc :
If you implement this method, but create an application for iOS 2.x, your dealloc method should release each object, but also should set the reference to this object to zero before calling super.
If you do not support iOS2.x, there is no need to set objects on nil in dealloc.
So, we summarize the Apple -viewDidUnload regarding -viewDidUnload and -dealloc :
- In
-viewDidUnload , nil properties (including IBOutlet properties) but do not free them - In
-dealloc release properties, but not zero (unless built for 2.x).