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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:34:32+00:00 2026-05-20T04:34:32+00:00

I need few clarification in iPhone memory management. Here is an example for setters;

  • 0

I need few clarification in iPhone memory management.

Here is an example for setters;
1).

-(void)setValue:(NSString*)input{
[value autorelease];
value = [input retain];
}

In this example, why we have to use autorelease?
Can we use like as follows?


if(value)
[value release];
value = [input retain];

In the first example, Why we should not release the memory for input
2).
If I use following statement; what is the retain count for value

NSString *value;
value = @"welcome";

After the above statement, just I am trying to set one more value. Then what will happen?

eg:
value = @"For testing";

3).
What is the different between 2) and 3)?

NSString *value;
value = [input1 retain];
...
...
value = [input2 retain];// Now what is the retain count for value

4).
If I use following statement, why the app is getting crash?


NSString *value = [[[NSString alloc] init] autorelease];
...
...

Thanks in advance..

  • 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-20T04:34:33+00:00Added an answer on May 20, 2026 at 4:34 am

    If “input” is the exact same object as “value” then calling [value release] could dealloc the object. So you must retain the new input value, release the old value, then assign the new value to the ivar:

    [input retain];
    [value release];
    value = input;
    

    After each of 2) and 3), the NSString *value points to a literal NSString object, the retain count will be 1 in each case, and releasing it is probably not a good idea

    After this code:

    value = [input2 retain];
    

    value is an alias to the input2 object. The thing to realize is that objects have retain counts, variables do not.

    As for your last case,

    NSString *value = [[[NSString alloc] init] autorelease];
    

    It creates an autoreleased empty string. If you reference that object again once the autorelease actually happens, you may get a crash because you’ll be referring to an object that doesn’t exist any more.

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

Sidebar

Related Questions

Windows Phone 7.1/7.5/Mango Silverlight App. Coming from here: Need clarification on using audio on
I've read several threads about this topic and need some clarification on a few
I'm creating a user-based website. For each user, I'll need a few MySQL tables
i need to write few applications about lowlevel videocard controling for my coursework. For
I need to initialize few objects, it can take a while so I want
How do you store file permissions in a repository? A few files need to
I need to deploy a few files that were checked in sometime ago (can't
I need to do a few very simple URL manipulations in Java. Like get
I need to deploy a few .net dlls. They need to be put in
I need to read smallish (few MB at the most, UTF-8 encoded) XML files,

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.