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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:03:38+00:00 2026-05-31T21:03:38+00:00

I have a quick question about the dealloc() and viewDidUnload() methods. I notice a

  • 0

I have a quick question about the dealloc() and viewDidUnload() methods. I notice a lot of code examples, people seem to do different things.

Also, I might add that ARC is not an option.

(1) Should I set all the properties to nil in the dealloc() method including IBOutlets. For example, should I release the instance variable [_myArrary release] and also set self.myArrary = nil.

(2) In viewDidUnload, I think I must set all IBOutlets to nil, and also anything that is created in viewDidLoad. However, what about myString, lets say it is intialized in another method after viewDidLoad is called. Should I set that to nil?

If I have some properties declared as such:

@property (nonatomic, retain) IBOutlet UITableViewCell *myTableCell;
@property (nonatomic, retain) IBOutlet UILabel *myLabel;
@property (nonatomic, retain) NSArray *myArrary;
@property (nonatomic, retain) NSString *myString;

I synthesize them as such:

@synthesize myArrary = _myArrary;
@synthesize myTableCell;
@synthesize myLabel;
@synthesize myString;

- (void)viewDidLoad
{
    [super viewDidLoad];

    _myArrary = [NSArrary alloc] initWithObjects:@"testObject", nil];
}

- (void)viewDidUnload
{
    self.myArrary = nil;

    self.myTableCell = nil;

    self.myLabel = nil;

    [super viewDidUnload];
}

- (void)dealloc
{   
    [_myArray 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-31T21:03:39+00:00Added an answer on May 31, 2026 at 9:03 pm
    1. It shouldn’t matter if you set the properties/variables to nil in dealloc because once the object is deallocated you won’t be able to access them anyway. With retain properties, doing

      self.varname = nil;

      will both release the variable and set it to nil. A lot of people prefer to only release them, I prefer to set retain properties to nil for consistency.

    2. In viewDidUnload you should release and set to nil anything that is unneeded and that will be recreated when the view loads again. This is not a strict rule, but good practice to keep as much memory available as possible. If your string will be recreated in viewDidLoad and you won’t need to access it until the view is loaded again, then you should probably release it (and I would set it to nil for safety).

      Another note, viewDidUnload does not always get called before dealloc. So you should be releasing every property/variable is dealloc, even if it is also released and set to nil in viewDidUnload. In order to make sure you won’t leak when your class is deallocated, your dealloc function for that code should look like this:

      - (void)dealloc {
          [myTableCell release];
          [myLabel release];
          [_myArray release];
          [myString release];
      
          [super dealloc];
      }
      

      Setting them to nil is also acceptable, but only if you use the synthesized setter, because this also releases the variable.

      self.myLabel =  nil;
      

      is fine, but

      myLabel = nil;
      

      is leaky.

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

Sidebar

Related Questions

i have what i hope is a quick question about some code i am
I have a quick question about Java synchronization. Please assume the following code: public
I have a quick question about Java synchronization. Please assume the following code: public
I have a quick question about TreeSet collections and hashCode methods. I have a
I have a quick question about the two examples below. Currently I am using
I have a quick question about altering the build path as the code is
A quick question about best practice with PHP classes. I have seen people use
I have a quick question about fetching results from a weakly typed cursor and
I have a quick question about encapsulating specific types with typedef . Say I
I just have a quick question about how to get the length of 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.