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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:02:32+00:00 2026-05-28T17:02:32+00:00

When you use Xcode’s feature and drag from the nib file into the .h

  • 0

When you use Xcode’s feature and drag from the nib file into the .h and .m file, Xcode adds the code in the dealloc and viewDidUnload. It adds extra code I do not normally add. I am just curious if this extra code is needed.

I would have done [self setDisplaySlider:nil] and not disp = nil and [disp release].

Is this necessary? I don’t think you have to release disp.

@interface ViewController : UIViewController
{
   IBOutlet UISegmentedControl *disp;    
}

@property (retain, nonatomic) IBOutlet UISegmentedControl *displaySlider;

@end

- (void)viewDidUnload
{
    [self setDisplaySlider:nil];
    [disp release];
    disp = nil;
    [super viewDidUnload];
}

- (void)dealloc {
    [displaySlider release];
    [disp release];
    [super dealloc];
}
  • 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-28T17:02:33+00:00Added an answer on May 28, 2026 at 5:02 pm

    In my opinion you provided a class with extra code. I’ll try to explain.

    First of all, in your previous you have two different IBOutlet. I think that the first one has been added by you.

    IBOutlet UISegmentedControl *disp;
    

    The second one, instead, has been added by Xcode when you made the drag and drop oeration.

    @property (retain, nonatomic) IBOutlet UISegmentedControl *displaySlider;
    

    First consideration

    The term IBOutlet is only a placeholder for Xcode. By means of it, Xcode helps you to connect an instance variable to a graphical element.

    When I use outlet connections I usually supplying an accessor like @property (retain, nonatomic) IBOutlet UISegmentedControl *displaySlider; (as Xcode did) because if not you could incurr in memory leak problems.

    Second consideration

    The code Xcode has provided is right. When you made the drag operation you linked toghether displayController instance variable with your graphical element. To balance this connection, that instance variable has to be released in dealloc method like the following:

    [displayController release];
    

    In addiction, Xcode added [self setDisplaySlider:nil]; because in memory warning situations viewDidUnload method could be called. No problem here because whene the controller is loaded in memory again, the outlet connection is restored.

    The difference between the two method calls can be read in Advanced Memory Management doc and release-or-set-to-nil-retained-members. Note that if you do this:

    [displayController release];
    

    you access directly your instance variable called displayController, while if you do this:

    [self setDisplaySlider:nil]; // or self.displaySlider = nil;
    

    you access the accessor (the setter method in this case) for that instance variable. It’s not the same (to avoid confusion see the code I provided).

    So, this is the code I would use (I added some comments to guide you):

    //.h
    @interface ViewController : UIViewController
    {
        UISegmentedControl *disp; // instance variable called disp
        // (A) now this is no longer necessary, new compile mechanism will create an instance
        // variable called _displaySlider under the hood
    }
    
    @property (retain, nonatomic) IBOutlet UISegmentedControl *displaySlider;
    
    @end
    
    //.m
    @synthesize displaySlider = disp;  // I say to Xcode to create a setter and a getter to access the instance variable called disp as written in @property directive
    // no longer necessary for (A)
    
    - (void)viewDidUnload
    {
        [super viewDidUnload];        
        [self setDisplaySlider:nil]; // I call the setter method to release the UISegmentedControl
    }
    
    - (void)dealloc {
        [disp release]; // I release the UISegmentedControl directly
        // if you choose the (A) mechanism simply do
        // [_displaySlider release];
        [super dealloc];
    }
    

    Hope it helps.

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

Sidebar

Related Questions

I use Xcode's Build and Archive feature to create an .ipa file that I
I started to use Xcode 4.2 and i have problems with generating code coverage.
I am new to iPhone app. I was told not to use Xcode storyboard
When I use Xcode (3.1.4 Leopard) to code in plain C (using the Standard
I'm just starting to use Xcode 4, and I'm trying to find the file
I develop for iOS and use XCode 3.2.5, GCC 4.2. UPD This code works:
I've been trying to use Xcode 4 on my 1GB Mac Mini. It's not
I use xcode 4.2 and this use ARC (Automatic Reference Counting). This is not
I usually use XCode but was having a problem opening a file with this
I started to use Xcode 4.2 and it seems you can't use anymore dealloc

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.