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

  • SEARCH
  • Home
  • 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 8984691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:10:07+00:00 2026-06-15T21:10:07+00:00

I am adding a ViewControllers view as a subView to another ViewController, Example :

  • 0

I am adding a ViewControllers view as a subView to another ViewController,

Example :

In FirstScreen viewcontroller i do this,

         [self.view addSubview:self.secondScreen.view]; 

And Once i remove it from FirstScreen i do this

         [self.secondScreen.view removeFromSuperView];
          self.secondScreen=nil;  

But While Adding the subView ViewDidLoad method is called but while removeFromSuperView ViewDidUnLoad is not called.

My Question

1) will all my objects in my secondScreen will get deallocated once i set the instance self.secondScreen to nil

2)Is it safe to do like this so that i wont get any leaks or memory warning

  • 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-15T21:10:08+00:00Added an answer on June 15, 2026 at 9:10 pm

    Assuming that your app supports from iOS 5.0 onwards, you need to add it as,

    [self addChildViewController:self.secondScreen];
    [self.view addSubview:self.secondScreen.view]; 
    

    Similarly for removing you can use removeFromParentViewController and then remove from superview. Check apple documentation here.

    ViewDidUnLoad is deprecated from iOS 6.0 onwards and will not get called. Check the documentation here.

    Regarding your questions,

    1) will all my objects in my secondScreen will get deallocated once i
    set the instance self.secondScreen to nil

    Once you are done with self.secondScreen class, it will start releasing objects inside this class once you set it to nil. If you are using ARC, you dont have to worry much about releasing. OS will take care of those things.

    2)Is it safe to do like this so that i wont get any leaks or memory
    warning

    Yes, this is fine if you are using ARC. For non-ARC, you need to make sure that you have released all variables properly in this class. Make sure the retain/release are all balanced in that case.

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

Sidebar

Related Questions

In application:didFinishLaunchingWithOptions: I'm adding a split view: [self.window addSubview:splitViewController.view]; [self.window makeKeyAndVisible]; splitViewController comes from
I'm adding subviews with tap gestures: from UIView class(masterButton): [self addSubview:self.button]; // Add gesture
I'm adding a ViewController as a subview to my main view, like so: UIStoryboard
Hey, I'm adding a UIViewcontroller as a subview of my current view. With something
NavigationControllers have ViewController stacks to manage, and limited animation transitions. Adding a view controller
Similar to this question: Adding subview, gets delayed? But I don't think you can
I have successfully loaded a view from an xib file on to a window(another
I'm creating an array of view controllers, adding them to a UINavigation Controller, and
I have a custom viewController called SourceListViewController, and I'm adding it into a UINavigationController,
I have a viewController (Planner) that loads two view controllers (InfoEditor and MonthlyPlan) when

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.