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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:13:05+00:00 2026-06-17T10:13:05+00:00

Please solve this. NSString *S1 = @abc; //retain count of s1 ?? NSString *S2

  • 0

Please solve this.

NSString *S1 = @"abc";
//retain count of s1 ??

NSString *S2 = [S1 copy];
//retain count of s2 and s1 ??

NSString *S3 = [S2 copy];
//retain count of s3 and s2 ??

NSString *S4 = [S3 retain];
//retain count of s4 and s3 ??

NSString *S1 = @"xyz";
//retain count of s1, s2, s3 and s4 ??

Do not suggest retainCount because i believe that does not give exact result.

  • 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-06-17T10:13:07+00:00Added an answer on June 17, 2026 at 10:13 am

    Edited thanks to clarification from @KurtRevis

    Assuming ARC is off, of course, you could test this yourself. But you may not understand why you are getting these results. Here is what you should be getting and why.

    NSString *S1 = @"abc";
    //retain count of s1 ??
    

    S1 is a constant string literal that will never go leave memory as long as your app is running. So retain count is sort of irrelevant.

    NSString *S2 = [S1 copy];
    //retain count of s2 and s1 ??
    

    S1 is unchanged. S2 is a copy of S1 with retain count of 1, with no autorelease.

    NSString *S3 = [S2 copy];
    //retain count of s3 and s2 ??
    

    S2 is unchanged at 1 with no autorelease. S3 is a copy of S2 with retain count of 1, with no autorelease.

    NSString *S4 = [S3 retain];
    //retain count of s4 and s3 ??
    

    S4 and S3 now point to the same object. And that one object now has a retain count of 2, with an autorelease. Once autorelease is triggered, it will have a retain count of 1, and will not be deallocated.

    NSString *S1 = @"xyz";
    //retain count of s1, s2, s3 and s4 ??
    

    The old object S1 used to point to is unchanged, it’s a persistant string in memory. And now S1 points to a new string which is treated the same way as what S1 used to point to.


    Or just save yourself some headaches and use ARC 🙂

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

Sidebar

Related Questions

Please help me solve this problem with capybara I have a button like this
Can any one please help me solve this. I am resizing some flash object/embed
I have a long string, ex: Please help me to solve this problem. This
Please solve that mystery to me.. I'm having the simplest layout of webform, meaning
Could someone please help solve this problem?
please help me solve this issue. I have a client using WCF. I don't
Could you please help me solve this problem? I've been trying to post a
Please help me solve this file path conflict: As you know, many HTML pages
Please help me solve my big problem. in my on-line shopping project i created
Here is a way to solve Euler problem 43 (please let me know if

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.