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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:44:12+00:00 2026-05-24T20:44:12+00:00

I’m still a tad confused on iPhone memory management. It’s not a huge issue

  • 0

I’m still a tad confused on iPhone memory management. It’s not a huge issue as it doesn’t deal with the most common use cases (I just release in dealloc, and set to nil in viewDidUnLoad). But let’s get this straight:

Suppose I got an instance variable that is retained and synthesized. And I allocate it.

If I set it to nil, does that mean the object is deallocated in memory? It’s gone? Because someone told me setting it to nil only sets the pointer to nil, and doesn’t deallocate it from memory.

I know when the owner count is set to 0, the memory is deallocated.. That’s correct, right? If not, I think my entire universe may have been broken =)

  • 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-24T20:44:13+00:00Added an answer on May 24, 2026 at 8:44 pm

    When a piece of memory has a retain count of 0 associated with it, then it is available for reuse (so it is deallocated).

    Suppose I got an instance variable that is retained and synthesized. And I allocate it.

    In your .h file:

    @property (nonatomic, retain) SomeObject myInstanceVariable;
    

    In your .m file:

    @synthesize myInstanceVariable;
    
    self.myInstanceVariable = [[SomeObject alloc] init];
    

    This statement does two things – firstly it allocates memory for “SomeObject” and in the process sets the retain count on that memory to 1. Secondly it assigns a pointer to that memory to the ivar via the synthesized setter method. The synthesized setter method calls release on any current memory pointed to by the iVar, which reduces its retain count by 1, and then assigns the pointer to the new object to the iVar and increments its retain count. Thus after this statement the retain count is 2

    If I set it to nil, does that mean the object is deallocated in memory? It’s gone? Because someone told me setting it to nil only sets the pointer to nil, and doesn’t deallocate it from memory.

    self.myInstanceVariable = nil;
    

    This sets the iVar via the synthesized setter method, which reduces the retain count of the current value by 1 and then sets the new value (nil) on the iVar. Thus in this example these two statements one after the other result in memory that still has a retain count of 1 and thus is not available for reuse by the operating system.

    So if you allocate an object yourself and then also assign it to a retain property, then you should explicitly release it after assigning it to the retain property. (and in your dealloc method also release the ivar to cater for the property).

    self.myInstanceVariable = [[[SomeObject alloc] init] autorelease];
    

    this allocates some memory (increasing its retain count to 1) then assigns a pointer to that memory to the iVar via the setter (increasing the retain count to 2) but also flags it for autorelease – which means it is added to the autorelease pool and released when your thread loses control (which will reduce the retain count by 1). Then when your object (self) is released, the dealloc method (if implemented properly) will release the ivar (myInstanceVariable) and then the retain count will go to 0 and the memory you originally allocated will be deallocated.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.