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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:00:01+00:00 2026-06-01T19:00:01+00:00

I am curious about how retain/release work internally. On the face, it seems like

  • 0

I am curious about how retain/release work internally. On the face, it seems like there’s an integer related to each instance of an NSObject, which gets increased and decreased when you call -retain and -release, respectively.

But taking a look at NSObject, the only instance variable it has is the isa variable, for determining its class type.

So where are retain counts for individual objects stored? Not that I’m going to muck around with it, but just for my own edification.

Is it stored with the NSObject, but hidden away in some Objective C implementation detail? If so, that seems like a bad design to me. One should be able to create their own root class and handle their own retain/release counting in a similar fashion (not that it’s a good idea–one would have to have a very good reason not to use NSObject).

  • 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-01T19:00:04+00:00Added an answer on June 1, 2026 at 7:00 pm

    The storage location for the retain count depends on both the runtime in use and the class implementation.

    For Apple’s Objective-C runtime, you can figure out a lot by digging into the source code of the Objective-C runtime.

    For example, if you’re using ARC (and I think even if you’re not), the reference counts for most objects are stored in hash tables. Have a look at the _objc_rootRetain function in runtime/objc-arr.mm. I don’t know exactly why they did this. Perhaps it’s a way of keeping retain counts together for better cache behavior (which is important under ARC because ARC adjusts retain counts more often than non-ARC code usually does).

    However, some classes override retain and related methods and store the retain count elsewhere. For example, when debugging a memory leak I discovered that CALayer does this. Instead of using the runtime’s normal retain count mechanism, a CALayer stores its retain count in a private C++ implementation object. This is rather frustrating because it means the Instruments Allocations instrument doesn’t log retains and releases of CALayer objects.

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

Sidebar

Related Questions

I'm curious about whether there is any way to fake out Array.isArray() with a
I am a little curious about the cute little kaleidoscopic images associated with each
Just curious about how to overload them. The opAssign operators are like addAssign(+=) and
I'm curious about string literals. I've read that in the case of something like
Just curious about what would be the django way of achieving the following :
I am curious about the Custom To-Many Relation Accessors. It makes sense that the
I am curious about how many of you folks incorporate mocking of objects (frameworks
I was curious about how other people use the this keyword. I tend to
I'm curious about people's approaches to using stored procedures in a database that is
I'm curious about OpenID. While I agree that the idea of unified credentials is

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.