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 8022321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:14:02+00:00 2026-06-04T22:14:02+00:00

My iOS app is navigation-based with the following structure: @interface ViewControllerA : UIViewController @property

  • 0

My iOS app is navigation-based with the following structure:

@interface ViewControllerA : UIViewController
@property (strong,nonatomic) ViewControllerB *viewControllerB;
@property (strong,nonatomic) ViewControllerC *viewControllerC;
...

viewControllerB and viewControllerC get instantiated before ViewControllerA‘s navigationController pushes them.

In my understanding, everything that is retained in ViewControllerA should be set to nil in ViewControllerA‘s viewDidUnload.
Should I do the same to child view controllers? Like this:

-(void)viewDidUnload
{
    self.viewControllerB=nil;
    self.viewControllerC=nil;
}

I found an issue when there was “received memory warning” initiated from viewControllerC.
Afterward, viewDidUnload of the parent view controller (i.e. viewControllerA) was called, thereby setting nil to ‘viewControllerB’. Unexpectedly, viewDidUnload of viewControllerB is also called. So I got “message sent to deallocated object” if I set nil to viewControllerB‘s subviews (in viewControllerB‘s viewDidUnload).

Does it mean that I should not set nil to child view controllers?
What is the best practice for memory management in this situation?

P.S. I use ARC.

  • 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-06-04T22:14:04+00:00Added an answer on June 4, 2026 at 10:14 pm

    After a call to viewDidUnload, a UIViewController should maintain its state, i.e. not releasing anything that cannot be easily recreated.
    Usually you set to nil any data that is related to the view hierarchy, for example strong references to some subviews or custom data created in the viewDidLoad. In you example, your parent controller A is expected to be able to recover after viewDidUnload was called, meaning that in the future a call viewDidLoad will restore your controller and not crash.

    Moreover, all view controllers are registered for memory warning notifications, so when a memory warning occurs they can unload any views that isn’t currently shown. I don’t know if the order the view controllers are called is deterministic, for example called starting from the top view controller, so you should be cautious when setting a nested UIViewController to nil in the parent controller viewDidUnload.

    But as you must maintain the state of yours controllers after viewDidUnload, you must not set your child controllers to nil. What you must do is relinquish every strong references you have on the controller subviews (for example a strong reference to a UILabel etc.), but not relinquish the controller itself.

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

Sidebar

Related Questions

I'm diving into iOS development and I'm building a navigation based app that wasn't
I'm working with a Navigation Controller based iOS app. There are multiple tableView screens
My iOS app has been rejected and I got the following message from Apple:
I'm trying to determine the best starting structure (navigation, windows based, something else) for
I’m designing the interface for an iOS app in which there are both hierarchical
Hello i'm trying to make a simple ios app with tabs and navigation .
I've been following the Build your second iOS app tutorial step for step and
My app is a Navigation based application. The main menu contains the list view
My iOS app is supposed to perform the following two tasks at the same
I'm obviously missing something... In my iOS app, I push a UIViewController onto a

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.