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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:27:13+00:00 2026-05-29T13:27:13+00:00

normally when I’m using a viewcontroller that will push the current viewcontroller out of

  • 0

normally when I’m using a viewcontroller that will push the current viewcontroller out of the way, I use a UINavigationController and push/pop the new viewcontrollers and let them handle all the dealloc themselves.

However, for example, in this case, I have a MainViewController, which is the default view when the app starts up. I have a second view, called SecondaryViewController, that is a popup on the main screen (sort of like a lightbox).

Here is the code to illustrate:

//From within mainViewController:
secondaryViewController = [SecondaryViewController alloc] initWithNibName:@"SecondaryViewController" bundle:nil]; 
[self.view addSubview:secondaryViewController.view];

The secondaryViewController interface looks like this:

//interface
@interface SecondaryViewController : UIViewController
{
    IBOutlet UILabel *httpLabel;
    IBOutlet UIScrollView *scrollView;
}
@property(retain, nonatomic) IBOutlet UILabel *httpLabel;
@property(retain, nonatomic) IBOutlet UIScrollView *scrollView;

As for the implementation, I have the @synthesize for the @property ivars, but I’m not doing any manual allocs. However, I did put a dealloc method:

- (void)dealloc
{
    [httpLabel release];
    [scrollView release];
    [super dealloc];
}

But I’m not sure I need the above.

So my questions would be the following:

1) Do I need the above dealloc method in this case? Or more generally, when would a subview need a dealloc method?

2) If I do or dont need it, does it depend on whether I’m adding the secondaryViewController via addSubview or pushViewController? For instance, if I wanted to replace the entire mainViewController, with this:

[self.navigationController pushViewController:secondaryViewController animated:NO]

Would the secondaryViewController need a dealloc method?

Thank you!

  • 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-29T13:27:14+00:00Added an answer on May 29, 2026 at 1:27 pm

    Yes, you do need the dealloc method exactly as you have it, in this case. You are on the right track because you’re assuming that since you are not doing any manual allocating, you don’t need to do any dealloc/releasing… however, by specifying the property as (retain, nonatomic), you are doing implicit retaining.

    This means that if you ever set those properties, what’s actually occurring under the covers is something like this:

    -(void)setHttpLabel:(UILabel *)newlabel
    {
      if (newLabel != httpLabel)
      {
        [httpLabel release];
        httpLabel = [newLabel retain];
      }
    }
    

    As you can see, your synthesize is causing a retain to occur on an object. If you never balance that retain out with a release, it will leak. So the only logical place to put it, is in your dealloc method. This creates the circle of life.

    If you never set these properties and don’t have release in dealloc, then it won’t leak anything, but you obviously wouldn’t want to make those assumptions.

    If you didn’t have any retain properties or any manual allocing of ivars, then and only then, can you nuke the dealloc method.

    Hope that helps.

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

Sidebar

Related Questions

Normally using parse_str('name=me&hungry=yes') will make a variable $name and hungry be equal to 'me'
Normally the easiest way to debug is using printf . What can I do
Normally, when using the XMLSerializer to automagically serialize an ISerializable object, a .dll file
Normally to realized linked objects, i usually use getter and setter methods and this
Normally if you have showuserlocation enabled, and going to mapview, there will blue point
Normally I'd use carrierwave, but they do not officially support jruby, and I've been
Normally i would only use alphanumeric with - and _ in any html class
Normally, I use the following code to serialize object to XML file. Everyday, I
Normally when an image comes into my site I save it as jpg using
Normally you create a function using cfscript like: <cfscript> function foo() { return bar;

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.