Question: I am new to iPhone development. 

I am using some buttons and labels in my app. I am releasing all these buttons and labels in dealloc function.  

I am also releasing them in viewDidUnload.

```
- (void)viewDidUnload
{
[super viewDidUnload];
self.ans1 = nil;
self.ans2 = nil;
self.ans3 = nil;
self.ans4 = nil;
self.button = nil;
self.button2 = nil;
self.button3 = nil;
self.button4 = nil;
}

```

I just want to know that it is good for memory management or it makes no difference to memory management.  

And why we use that?? 

Thanks in advance..!!

Answer: 
it is not the view controller that is unloaded when viewDidUnload is called but only its **view**. **The view controller stays alive until it is deallocated.**

In viewDidUnload, you have to release those objects that are part of the view and everything that can and will be recreated in viewDidLoad (because viewDidLoad will be called again when the view controller need to recreate its view). This includes all your outlets. You also have to set these variables to nil to avoid overreleasing them.

Because in dealloc, you should release all objects your view controller retains, including those you included in viewDidUnload.
viewDidUnload is used to release anything that you might have made when the view is created - this included things in viewDidLoad but also includes and IBOutlet properties that are created from inside a xib file. these should all be released and set to nil in viewDidUnload.

Anything else should just be released in dealloc.

The idea is that if viewDidUnload is called to free some memory, the view can be recreated again completely from your viewDidLoad method.

Also see this question;

[memory management on the iPhone with viewDidUnload](https://stackoverflow.com/questions/3490495/memory-management-on-the-iphone-with-viewdidunload)