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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:09:45+00:00 2026-05-12T14:09:45+00:00

In Objective C, is there a way to determine at runtime, if an object

  • 0

In Objective C, is there a way to determine at runtime, if an object is retained, which other object might be retaining that object?

Or to phrase it a little differently:

If there are leashes on the dog is it possible to know who is holding the leash?

Assume you have this hypothetical scenario:

MyObjectOne

and

MyObjectTwo

inside the implementation of MyObjectTwo is something like

- (void)setFirstObject:(MyObjectOne *)firstObj {
 [firstObj retain];
    // do stuff with object and under certain conditions don't release it    
}

Now elsewhere in the code there might be other places which create and retain the objects

// Create the two objects
myFirstObject = [[MyObjectOne alloc] init];   
mySecondObject = [[MyObjectTwo alloc] init];

// ...
// Some process requires retaining the first object 
[myFirstObject retain]

// ...
// some other place requires passing the first object to the second object
// at which point the first object is retained by the second object 
[mySecondObject setFirstObject:myFirstObject];

// ...
// further on the first object is released
[myFirstObject release]

At this point theoretically myFirstObject should have a retain count of 1 because it was retained inside MyObjectTwo. Is it also, possible to know WHAT is retaining the object? In other words it is possible to know that myFirstObject has a retain count of 1 AND it is currently retained by mySecondObject. Is there a convenience method for finding this information out? Is it possible to have conditional code that works like this psuedo code:

if (MyObjectTwo is retaining MyObjectOne)
{
 // do something in particular
}

Take this a few steps further and say myFirstObject has a retain count higher than 1 and that there are other objects MyObjectThree and MyObjectFour which behave similar to MyObjectTwo in that they have methods that can retain MyObjectOne. And now assume that there are multiple instances of MyObjectTwo, MyObjectThree and MyObjectFour some which are retaining the first object and some which are not. Is there a way to know who and what is doing the retaining?

Still learning, so my syntax might not be 100% correct but hopefully the question is clear.

  • 1 1 Answer
  • 1 View
  • 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-12T14:09:45+00:00Added an answer on May 12, 2026 at 2:09 pm

    No, you can’t do that. Objects do not keep track of who has retained them, and there isn’t always such an object, since you can call retain from inside a plain vanilla C function, which has no associated object.

    If you want to keep track of who is retaining an object, you need to do this yourself. Every time you retain, you add yourself to a list of retainers, e.g. an NSArray inside the object being retained.

    I don’t know exactly what you’re trying to do, but you’re almost certainly going about it the wrong way. Figuring out who is retaining what is not really a useful thing to know most of the time, and there’s probably a much better way of doing what yo uwant.

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

Sidebar

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.