Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6223089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:25:40+00:00 2026-05-24T08:25:40+00:00

If I have an NSArray of UIViewControllers and send release to the array, will

  • 0

If I have an NSArray of UIViewControllers and send release to the array, will that call viewDidUnload or dealloc for each of the UIViewControllers? or neither?

Here’s what I’m doing:

- (void) viewDidLoad {
   UIViewController* profileController = [[ProfileController alloc] init]; 
   ..........
   //all the other controllers get allocated same way

    self.viewControllers = [[NSMutableArray alloc] initWithObjects: profileController, dietController, exerciseController, progressController, friendsController, nil];

    [profileController release];
    //other controllers get released same way ....
}

- (void) dealloc {
   [viewControllers release];
   NSLog("DEALLOC!");
   //I know dealloc is being called
   //what happens to the view controllers? 
}

I put a breakpoint in the viewDidUnload and dealloc methods for each of these view controllers, and they don’t get called.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:25:40+00:00Added an answer on May 24, 2026 at 8:25 am

    As pgb mentioned, you are confusing the two concepts of memory management and view controller life cycle. viewDidUnload will be called whenever the view controllers view is unloaded, which of course will only happen if the view is loaded. In the absence of displaying any of the view controllers you should not expect to see viewDidUnload called at all.

    You very much should expect to see dealloc called though!

    Your problem is with the initialisation of the viewControllers array:

    self.viewControllers = [[NSMutableArray alloc] 
                                   initWithObjects: profileController,
                                                    dietController,
                                                    exerciseController,
                                                    progressController,
                                                    friendsController,
                                                    nil];
    

    Assuming that viewControllers is a property that is using the retain attribute, this will leak the array, and thus all the array’s contents. The problem is that you have alloc’d a mutable array (thus retain count = 1), then you are assigning it to the viewControllers property which will increment the retain count.

    In your dealloc method you (correctly) release the array, but this will merely decrement the retain count to one.

    My suggested fix is to add autorelease to the above code:

    self.viewControllers = [[[NSMutableArray alloc] 
                                   initWithObjects: profileController,
                                                    dietController,
                                                    exerciseController,
                                                    progressController,
                                                    friendsController,
                                                    nil] autorelease];
    

    After making this change you should expect to see dealloc being called on the view controllers. You should also expect to see viewDidUnload called as the views of these view controllers are unloaded (for example, as they are popped off of the stack in a navigation-controller based application).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a couple UIViewControllers that I am trying to access an array inside
I have an NSArray of (Product) objects that are created by parsing an XML
I have a view-based app that just does one thing : show a array
I have an nsarray that when I NSLog it from one of my methods
I have an nsarray that when I NSLog it from one of my methods
Hey all, I have an array that holds all of the .aif file paths
I have an NSArray and I'd like to create a new NSArray with objects
I have an NSArray of Foos in an Objective-C program. I would like to
I have an NSArray of NSDictionary objects which I would like to be able
If I have an NSArray with some values in them. Is there a way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.