I wonder what the -(void)viewDidUnload is good for. Could I not just release everything in -dealloc? If view did unload, wouldn't -dealloc be...

How It Works

Get an answer in three easy steps. Here's how it works...

Ask Your Question

1. Ask Your Question

Enter your programming question at the top of this page and click Get An Answer.

Pick Your Priority

2. Pick Your Priority

Tell us how quickly you want your programming question answered.

Get An Answer

3. Get An Answer

Connect with your programmer via online chat or telephone call.

Answer

Customer

I wonder what the -(void)viewDidUnload is good for. Could I not just release everything in -dealloc? If view did unload, wouldn't -dealloc be called anyways?

Posted
Rashid Mohammad
Programmer

In addition to what has already been indicated, I wanted to elaborate more about logic behind -viewdDidUnload.

One of the most important reasons for implementing it is that UIViewController subclasses commonly also contain owning references to various subviews in the view hierarchy. These properties could have been set through IBOutlets when loading from a nib, or programmatically inside -loadView, for instance.

The additional ownership of subviews by the UIViewController means that even when its view is removed from the view hierarchy and released to save memory, through which the subviews are also released by the view, they will not actually be deallocated because the UIViewController itself still contains its own outstanding retaining references to those objects as well. Releasing the UIViewController's additional ownership of these objects ensures they will be deallocated as well to free memory.

The objects that you release here are usually recreated and set again when the UIViewController's view is re-loaded, either from a Nib or through an implementation of -loadView.

Also note that the UIViewController's view property is nil by the time this method is called.

Posted
Customer

Great !!!

Posted

quoteTestimonialsquote

About ExpertHelp

ExpertHelp is changing the way you connect with service professionals.

Whether you have a quick question while preparing your taxes, troubleshooting a computer problem, or need to hire an attorney, ExpertHelp is the most convenient and affordable way to connect with the right service professional to get the job done.

ExpertHelp has been in business since 2011, is an A+ Rated Better Business Bureau accredited member, and offers a 100% satisfaction guarantee on every question you ask!

More Programming Questions...

Ask Your Programming Question & Get An Answer Now!