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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:22:30+00:00 2026-05-19T06:22:30+00:00

I would like to know in what situation did you use -retainCount so far,

  • 0

I would like to know in what situation did you use -retainCount so far, and eventually the problems that can happen using it.

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-05-19T06:22:31+00:00Added an answer on May 19, 2026 at 6:22 am

    You should never use -retainCount, because it never tells you anything useful. The implementation of the Foundation and AppKit/UIKit frameworks is opaque; you don’t know what’s being retained, why it’s being retained, who’s retaining it, when it was retained, and so on.

    For example:

    • You’d think that [NSNumber numberWithInt:1] would have a retainCount of 1. It doesn’t. It’s 2.
    • You’d think that @"Foo" would have a retainCount of 1. It doesn’t. It’s 1152921504606846975.
    • You’d think that [NSString stringWithString:@"Foo"] would have a retainCount of 1. It doesn’t. Again, it’s 1152921504606846975.

    Basically, since anything can retain an object (and therefore alter its retainCount), and since you don’t have the source to most of the code that runs an application, an object’s retainCount is meaningless.

    If you’re trying to track down why an object isn’t getting deallocated, use the Leaks tool in Instruments. If you’re trying to track down why an object was deallocated too soon, use the Zombies tool in Instruments.

    But don’t use -retainCount. It’s a truly worthless method.

    edit

    Please everyone go to http://bugreport.apple.com and request that -retainCount be deprecated. The more people that ask for it, the better.

    edit #2

    As an update,[NSNumber numberWithInt:1] now has a retainCount of 9223372036854775807. If your code was expecting it to be 2, your code has now broken.

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

Sidebar

Related Questions

I would like to know what will happen in the following hypothetical situation. Let's
i would like know some reference. I know i can googling it. but prefer
I would like to know what code to use to convert a double[] array
I would like to know, how can we change the SRC url for IFRAME
I would like to know if the following situation it's possible. Let's say I
I would like to know how I can provide the way to user for
I have a situation where I would like to know the value of the
I would like to know how to dispose objects correctly in the following situation.
I would like to know how I can only refresh a specific element in
Would like to know what a programmer should know to become a good at

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.