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

  • Home
  • SEARCH
  • 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 9054807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:46:48+00:00 2026-06-16T13:46:48+00:00

I must use a union containing a class pointer, but with ARC on, and

  • 0

I must use a union containing a class pointer, but with ARC on, and as very well explained here: __unsafe_unretained NSString struct var you have to set the field __unsafe_unretained.

That means, if I understand it well, you must manage yourself its lifecycle.

For example:

typedef union FOO {
    char                                    __char;
    __unsafe_unretained NSMutableArray *    __array;
    __unsafe_unretained BarClass *          __bar;
}

If I do something like:

FOO * foo = malloc(sizeof(FOO));
foo.__bar = [[BarClass alloc] init];
... // I have fun with foo.__bar
[foo.__bar release] // this was before ARC and does not work anymore
free(foo);

How do I release foo.__bar? Because with ARC I cannot call releaseor autorelease anymore?

  • 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-16T13:46:49+00:00Added an answer on June 16, 2026 at 1:46 pm

    The easiest way is to use a __bridge cast and CFRelease:

    CFRelease((__bridge void *)foo->__bar);
    

    Some other notes:

    1. Don’t use the names __char, __array, and __bar. All identifiers that begin with two consecutive underscores are reserved by the C standard.

    2. You need to retain the object too, before the end of the statement that creates it, because at the end of that statement, ARC will release it. The easiest way to do that is by abusing CFBridgingRetain:

      foo->__bar = (__bridge id)CFBridgingRetain([[NSObject alloc] init]);
      
    3. You might be better off just turning FOO into an Objective-C class so that it can hold strong references.

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

Sidebar

Related Questions

Some say that one must use UIApplication in main thread, but I don't see
I must use jQuery for first time.... <a class=Tag Resource href=http://localhost/ resource=http://localres/ property=prop>test</a> I've
I use the following query quite a lot but am pretty sure there must
I must use pkzip in my java program to zip (since standard java zip
When we must use DebuggerDisplay Attributes? What is the advantage of using this?
In my company I must use a Bll, Dal and model layer for creating
We are using Silverlight 4 (we must use it. :p ) with VS2010. AFAIK
2 Questions actually: I know i must use Stored Procedures as much as Possible,
I am programming a c project which must use the pow function defined in
I have a ~2MB file that my Google AppEngine server must use (not serve)

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.