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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:28:47+00:00 2026-06-06T23:28:47+00:00

Possible Duplicate: NSString retainCount is 2147483647 Let say i have an class named as

  • 0

Possible Duplicate:
NSString retainCount is 2147483647

Let say i have an class named as MyTestClass.h.

There are three NSString variables which are initialized different ways

Class structure is look like

@interface MyTestClass : NSObject {

  NSString *testString1;
  NSString *testString2;
  NSString *testString3;

}

@property (nonatomic, retain) NSString *testString1;
@property (nonatomic, retain) NSString *testString2;
@property (nonatomic, retain) NSString *testString3;

@end

MyTestClass.m

@implementation MyTestClass

@synthesize testString1, testString2, testString3;


-(id) init{

    self.testString1 = @"";

    [self setTestString2:@""];

    testString3 = @"";

}

Now i am planning to create an object of MyTestClass

MyTestClass *obj = [[MyTestClass alloc] init];

I think after this code line execution testString1, testString2 and testString3 retainCounts will be 1.

Am i correct my friends?

may i know that what will happened if i release testString3 ?

Any help on this is appreciated.

Thanks

  • 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-06T23:28:49+00:00Added an answer on June 6, 2026 at 11:28 pm

    Since you are using literal strings in this example retainCount is of no importance (not even as a delta) since those string objects aren’t actually ever going to be dealloc’d.

    However, if you were assigning a runtime allocated string to each of your properties, the first two would be retained, the third would not. Since your properties are declared as retain and you’re using dot syntax in one and the “setProperty” syntax in the other, the same setter is executed and the object passed to that setter is retained. The third example you’re simply setting the backing ivar for the property to the value on the right and not affecting it’s ownership.

    It’s worth noting, retainCount is only ever useful as a delta and shouldn’t be thought of as an explicit number. You should never explicitly check the value of retainCount, since it’s absolute value is unpredictable and of no use. You seem to understand this in your question, but it’s worth restating whenever dealing with retainCount to make sure all involved understand it.

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

Sidebar

Related Questions

Possible Duplicate: Properties declared as instance variables too? Let's say I have an objective
Possible Duplicate: NSString to NSDate I have a date in format Mon Jan 14
Possible Duplicate: NSJSONSerialization from NSString I have this old code, how do I accomplish
Possible Duplicate: Convert NSDate to NSString convert string to nsdate Currently I have this
Possible Duplicate: Objective-C constants: NSString comparison using ==? i have a textfiela nd label
Possible Duplicate: NSString stringWithFormat adding a percent a noob question here. I have a
Possible Duplicate: Convert from char* to NSString? I have char myChar = 'r' How
Possible Duplicate: Evaluate math expression in string? (NSString) Hey i have got this string
Possible Duplicate: Send NSString via Game Center i have been working on this for
Possible Duplicate: Do I need to release NSString generated using @“…”? There are two

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.