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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:55:28+00:00 2026-06-08T09:55:28+00:00

I’m writing a tool which would benefit from knowing which of a class’ instance

  • 0

I’m writing a tool which would benefit from knowing which of a class’ instance variables are declared __weak.

This information must exist somewhere at runtime, but is there any way of accessing it, documented or otherwise? (It’s for a tool, so I don’t care so much about it breaking with updates)

  • 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-08T09:55:30+00:00Added an answer on June 8, 2026 at 9:55 am

    Alright, here is a sample implementation, using a custom object implementation, that does a rudimentary check to see if an iVar is weak or not:

    BOOL iVarIsWeak(Class cls, Ivar ivar)
    {
        id classInstance = [cls new];
    
        // our custom base class properly tracks reference counting, no weird voodoo
        id refCounter = [CustomBaseClass new];
    
        object_setIvar(classInstance, ivar, refCounter);
    
        if ([refCounter refCount] == 2)
        {
            return NO;
        }
    
        return YES;
    }
    

    The above code is meant to be used with ARC enabled, while the following custom object code is not:

    @interface CustomBaseClass : NSObject
    
    +(id) new;
    +(id) alloc;
    -(id) init;
    
    -(id) retain;
    -(void) release;
    -(id) autorelease;
    -(void) dealloc;
    
    -(id) description;
    
    -(unsigned) refCount;
    
    @end
    
    
    // easy way to get sizeof
    struct CustomBaseClassAsStruct {
        voidPtr isa;
        unsigned volatile refcount;
    };
    
    @implementation CustomBaseClass
    {
        unsigned volatile  refcount;
    }
    
    +(id) new
    {
        return [[self alloc] init];
    }
    
    +(id) alloc
    {
        struct CustomBaseClassAsStruct *results =  malloc(sizeof(struct CustomBaseClassAsStruct));
        results->isa = self;
        results->refcount = 0;
        return (id) results;
    }
    
    -(id) init
    {
        [self retain];
    
        return self;
    }
    
    -(id) retain
    {
        ++refcount;
    
        return self;
    }
    
    -(void) release
    {
        if (--refcount == 0)
            [self dealloc];
    }
    
    -(id) autorelease
    {
        // sample implementation of autorelease
        dispatch_async(dispatch_get_current_queue(), ^{
            [self release];
        });
    
        return self;
    }
    
    -(unsigned) refCount
    {
        return refcount;
    }
    
    -(void) dealloc
    {
        free(self);
    
        // no call to [super dealloc], we are using custom memory-managment
    }
    
    @end
    

    This ONLY works for weak iVars. With a unsafe_unretained variable, it will give a false positive, my best guess for this is because __weak information is saved at runtime whilst unsafe_unretained information is not.

    I hope this helps!

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have a view passing on information from a database: def serve_article(request, id): served_article
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which 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.