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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:47:31+00:00 2026-06-18T11:47:31+00:00

I’m working with Box2D (C++) and I create an Objective-C object and assign it

  • 0

I’m working with Box2D (C++) and I create an Objective-C object and assign it to a Box2D body’s userData property, which is of type void*.

Now in some cases the void* userData may be the only active reference to that ObjC object. Therefore, because I used (__bridge void*) in the assignment, ARC is letting it go. That’s something I need to fix.

I’ve been pondering the options to prevent this from happening? I read Clang’s ARC documentation, specifically the parts about bridge casting (as well as Q&A on SO) as well as nodding to the various bridge casting constructs they consider to be “ill-formed”.

Still, my first thought was to use (__bridge_retained void*) in the initial assignment to userData. But that made me wonder how to balance that retain? I obviously can’t send release to the object.

So would I have to CFRelease() the object? Or would it need to be CFBridgingRelease()? Or are both illegal here?

Is a (__bridge_transfer void*) cast from userData to a temporary id type enough, perhaps while setting userData to NULL afterwards? Is that even a good idea?

I know the alternative would be to keep a separate NSArray/NSDictionary for the userData objects and keep them in synch with the lifetime of the Box2D body, adding and removing them in synch with their Box2D bodies.

But this feels like overkill because here I know what I’m doing, I know I need to +1 the object for as long as the Box2D body is active, and -1 the object when the Box2D body is removed. Plus I know that there are only two methods where the Box2D bodies are being added and removed, and direct access to userData is not even possible in my framework because all Box2D objects are hidden behind Objective-C interfaces/wrappers.

Setting possibly “ill-formed” aside for a moment, what would you recommend I should do in this situation?

  • 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-18T11:47:33+00:00Added an answer on June 18, 2026 at 11:47 am

    __bridge_retained means “Send this ARC object off into no-ARC land by retaining it”. You call this when you need to create an “untracked” void *. So, in your case, userData = (__bridge_retained void *)obj.

    __bridge_transfer means “Pull this object back from no-ARC land by releasing it”. You call this when you want to effectively invalidate the void *. So, obj = (__bridge_transfer id)userData. After this, the userData pointer is not safe to use; instead, you work only with obj. When obj goes out of scope, ARC will release it for the last time. This may entail creating a temporary id solely for this purpose.

    So, in your case, you do want to use __bridge_retained when you ship the object off into Box2D, and use __bridge_transfer when you want to invalidate the userData. If you need to access the userData as an Objective-C object but not invalidate the pointer, use plain __bridge.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
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 this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an autohotkey script which looks up a word in a bilingual dictionary

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.