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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:33:04+00:00 2026-05-24T23:33:04+00:00

I have a general question regarding memory management of properties. Currently, I always use

  • 0

I have a general question regarding memory management of properties. Currently, I always use properties without any explicit declaration of related ivars. And, for every retained or copied property I’m releasing its retain count both in dealloc and viewDidUnload methods:

-(void)dealloc{
  [self.myProperty release];
  [self.myOutlet release];
  [super dealloc];
}

- (void)viewDidUnload{
  [super viewDidUnload];
  self.myProperty = nil;
  self.myOutlet = nil;
}

Now, I know that only the outlets and properties retained by the main view should be set to nil in viewDidUnload, and the rest properties should be released in dealloc. But hey, why do I have to bother for every property where it must be released – in dealloc or in viewDidUnload? If some property will be released twice it’s OK because it wouldn’t crash the app by sending a message to nil object. Putting release in both places (dealloc and unload) saves time and prevents from bugs later when doing code refactoring and forgetting to change release place. Any critics and shouting on that? 🙂

  • 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-24T23:33:04+00:00Added an answer on May 24, 2026 at 11:33 pm

    If you’re using property accessors in -dealloc because you don’t have access to the ivar directly, you should do the same in -dealloc that you do in -viewDidUnload:

    self.myProperty = nil;
    

    The point of using -release in -dealloc is to avoid calling the accessor, which conceivably could have been overridden by a subclass to have side effects that you don’t want in -dealloc, when everything else from the subclass has already been deallocated. But if you’re already calling the accessor in -dealloc, you might as well use the setter to release the ivar and ensure that it’s done right.

    The difference between -dealloc and -viewDidUnload is that you’re still working with a complete, fully functional object in -viewDidUnload, whereas the object may already be partially deallocated in -dealloc.

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

Sidebar

Related Questions

I'm new to SharePoint and have a general question regarding list comparison. Currently, there
I have a very general question regarding the use of LINQ vs SQL to
I have general question regarding the use of pointers vs. references in this particular
I have a rather general question regarding the recognition speed of any dictionary using
I have a general question on the class definition and its use..THe below code
I have a general question about interpreters of functional languages: Are there actually any
I have a simple, general question regarding a real small issue that bothers me:
I have a question regarding an ArrayList of Integers, or primitive types in general.
I have a general question regarding UITableViews. here is my situation. I have a
I have a general question regarding the syntax of throwing an object. Consider: #include

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.