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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:49:27+00:00 2026-05-26T01:49:27+00:00

This is something I should have cleared up long ago, but I just need

  • 0

This is something I should have cleared up long ago, but I just need to know the best practice for deallocating in the following scenario.

In my header file I declare a reference to an IBOutlet as follows:

@interface Test : UIViewController {
    UIButton *_loginBtn;
}

@property (nonatomic, retain) IBOutlet UIButton *loginBtn;

And in the implementation file I associate the instance variable to the property and deallocate as follows:

@implementation Test

@synthesize loginBtn = _loginBtn;

...

- (void) dealloc {
    [_loginBtn release];
    self.loginBtn = nil;

    [super dealloc];
}

- (void) viewDidUnLoad {
    [_loginBtn release];
    self.loginBtn = nil;

    [super viewDidUnLoad];
}

Am I correct in the deallocating the instance variable and setting the property to nil and doing this in both the viewDidUnLoad and dealloc methods?

  • 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-26T01:49:28+00:00Added an answer on May 26, 2026 at 1:49 am

    There is no need for self.loginBtn = nil; in dealloc, the previous line released it. It is best not to use the property to release it in dealloc. The reason for releasing vs setting the property to nil is that the setter is a method call and the class is in the midst of tearing down and things may be unstable.

    In viewDidUnLoad release any properties that are IBOutlets with self.theOutlet = nil;, in this case the _loginBtn release]; is not needed and redundant. Also release any other objects that you can easily re-create.

    If properties are used they should be used for all accesses in the class with two exceptions: init and dealloc. In both of these cases the class is partially complete. In these two cases it is best to use the ivar directly in init (if necessary) and release in dealloc.

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

Sidebar

Related Questions

I feel like this is something I should already know, but I'm just not
I get the feeling this is probably something I should know but I can't
This is something stupid I probably should know, but Googling fails me: When compiling
This seems like it should be something I already know. We need to run
It seems like this should be something built into jQuery without the need for
This seems like it should be something very easy to do, but every time
I'm not sure if this is something I should do in T-SQL or not,
I guess the procedure should be something like this: declare @db varchar(100) declare @user
This might be something very straight forward and I really think it should work
It seems like there should be something shorter than this: private string LoadFromFile(string path)

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.