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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:56:59+00:00 2026-06-11T17:56:59+00:00

I created an empty iOS app on Xcode 4.4.1, and did the following: NSNumber

  • 0

I created an empty iOS app on Xcode 4.4.1, and did the following:

NSNumber *n1 = @1;
NSNumber *n2 = @2;
NSNumber *n3 = @3;
NSNumber *n100 = @100;

NSString *s = @"haha";
NSArray *a = @[n1, s];
NSDictionary *d = @{ @"ha" : @1, @3 : @"hello" };

NSLog(@"retain count of @1 is %i", [n1 retainCount]);
NSLog(@"retain count of @2 is %i", [n2 retainCount]);
NSLog(@"retain count of @3 is %i", [n3 retainCount]);
NSLog(@"retain count of @100 is %i", [n100 retainCount]);

NSLog(@"retain count of @\"haha\" is %i", [s retainCount]);

NSLog(@"retain count of array literal is %i", [a retainCount]);
NSLog(@"retain count of dictionary literal is %i", [d retainCount]);

and the result is:

retain count of @1 is 10
retain count of @2 is 4
retain count of @3 is 5
retain count of @100 is 1
retain count of @"haha" is -1
retain count of array literal is 1
retain count of dictionary literal is 1

so the retain count of array literal and dictionary literal is 1, and string literal is said to exist for the whole app’s running, so that’s why it is -1 (probably meaning MAX unsigned int), but the retain count of @1 actually come out as 7, 8, and 10 at different times. Is there a rule to it? I found that I can do [n1 retain] and [n1 release] as well, and it will increase and decrease the retain count accordingly.

  • 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-11T17:57:00+00:00Added an answer on June 11, 2026 at 5:57 pm

    I think this points to the reason why: every time @1 is encountered, it is something like [[[NSNumber alloc] initWithInt:1] autorelease], and it appears that it returns the same object. So when the following is done:

    NSMutableArray *arr = [[NSMutableArray alloc] init];
    for (int i = 0; i < 300; i++) {
        [arr addObject:@1];
    }
    

    the retain count actually becomes 610. And it is the same if the following is done:

    NSMutableArray *arr = [[NSMutableArray alloc] init];
    for (int i = 0; i < 300; i++) {
        [arr addObject:[[[NSNumber alloc] initWithInt:1] autorelease]];
    } 
    

    (Update: it is 610, because the retain count is increased by 1 by the usage of @1, and another time when it is retained by the array, so it is 600 times total). It suggests that any usage of @1 any where will increase the retain count, and this NSNumber object is probably placed in the autorelease pool the same equal number of times.

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

Sidebar

Related Questions

I have created an empty project (XCode 4.2 IOS SDK 5), I have added
I am building an Day View calendar app. I have already created the empty
I just created an empty iOS project and added a UIViewController with a nib
I am writing an iOS app for the iPhone in Xcode and I have
I created an empty Single View application using Xcode 4.2 on OSX Lion 10.7.2
I have created my first iOS app for the iPhone, as part of my
I created a empty test project (static library type) with enabling the unit test.
I created a empty project in ASP.Net and then I manually add it view,controller
I created an Empty Project in Visual C++, but now I need the Console
I have created an empty json object having an array itemlist(which further contains itemid

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.