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

  • Home
  • SEARCH
  • 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 102643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:59:53+00:00 2026-05-11T00:59:53+00:00

I have seen sample source code around that uses different ways of releasing/dealloc’ing objects,

  • 0

I have seen sample source code around that uses different ways of releasing/dealloc’ing objects, so I was wondering which way is deemed the ‘best’ one. A few options on -dealloc:

1) Release objects

- (void)dealloc {     [obj1 release];     [obj2 release];     [super dealloc]; } 

2) Set objects to nil

- (void)dealloc {     self.obj1 = nil;     self.obj2 = nil;     [super dealloc]; } 

3) De-allocate objects directly

- (void)dealloc {     [obj1 dealloc];     [obj2 dealloc];     [super dealloc]; } 

Which way is the best one? Pros and cons for each?

  • 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. 2026-05-11T00:59:53+00:00Added an answer on May 11, 2026 at 12:59 am

    Method 1 is the only recommended method. It’s also good practice to set them to nil AFTER you’ve released them.

    Method 2 only works for properties that manage their own object/value retaining, so it’s not universally applicable. And if you implement your own setter method that performs other actions when the property changes, you may get undesired side effects by calling it in [dealloc].

    Method 3 violates the reference-counting principle because it will deallocate the objects even if something else has a [retain] hold on them, so when the other objects access them next, your program will crash. You’re never supposed to call [dealloc] directly — let the runtime call it when the last owner calls [release].

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

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Well, just for completeness I will add here what I… May 11, 2026 at 11:50 am
  • added an answer The only reason I can think of is the message… May 11, 2026 at 11:50 am
  • added an answer How many product types do you expect? Do they each… May 11, 2026 at 11:50 am

Related Questions

I have seen sample source code around that uses different ways of releasing/dealloc'ing objects,
Every sample that I have seen uses static XML in the xmldataprovider source, which
I have seen simple example Ajax source codes in many online tutorials. What I
I have seen samples of closure from - What is a 'Closure'? Can anyone
Most of the MVC samples I have seen pass an instance of the view
How to build a simple recommendation system? I have seen some algorithms but it
I have seen examples of printing from a windows application but I have not
I have seen lots of questions recently about WPF... What is it? What does
I have seen Solutions created in Visual Studio 2008 cannot be opened in Visual
I have seen the references to VistaDB over the years and with tools like

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.