views:

662

answers:

2

They say:

// Release any retained subviews of the main view. // e.g. self.myOutlet = nil;

I've never seen that previously. so I wonder if they talk about nib outlets here?

+1  A: 

You don't have to if there is a reason to keep it around, but assuming you need to access the entity point to via the outlet if the view has been torn down then yes, you should release. Otherwise your view controller will be asserting a retain against all of the IBOutlets from yoour nib even though the nib itself has been unloaded, which prevents them from being dealloced. Since these objects may have textures and such backing them, and the iPhone uses main ram for video that can add up to a lot of wasted memory very quickly.

Additionally, if viewDidLoad is called again then a new object will have been created and assigned to that outlet when the nib is reloaded, so if you use it anywhere else (set properties in other objects to the object pointed to by the IBOutlet) then your app might end up in an inconsistent state.

Louis Gerbarg
+1  A: 

Similar to how anything you allocate in init should be unallocted in dealloc.

If you alloc memory in viewDidLoad, you should release it in viewDidUnload.

The issue gets confusing when you bring nib files into the picture. If you are manually loading the nib file, you should manually unload it and set all the IBOutlets to nil.

Kailoa Kadano