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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:27:43+00:00 2026-06-11T05:27:43+00:00

If I haven’t used ‘objc_setAssociatedObject’ to associate an object/key to an NSObject, and then

  • 0

If I haven’t used ‘objc_setAssociatedObject’ to associate an object/key to an NSObject, and then I call ‘objc_getAssociatedObject’, is this safe?

I’ve tested it in the simulator and it doesn’t crash, but I want to be sure.

And when I make the call:

 objc_setAssociatedObject(self, key, value, OBJC_ASSOCIATION_RETAIN);

Does the object that I associate with my NSObject get released when my NSObject is dealloc’d? (I’m using ARC).

  • 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-11T05:27:44+00:00Added an answer on June 11, 2026 at 5:27 am

    If there is no association in place, objc_getAssociatedObject will return nil.

    When you associate an object, it will use the semantics supplied in the last argument. For example, OBJC_ASSOCIATION_RETAIN will retain the object so it is not deallocated as long as the association is in place.

    When the object that holds the association (the first parameter to objc_setAssociatedObject) deallocs, it will break the association. When the association is broken, the retained object will be released (if it was retained to begin with).

    So, for your example:

    objc_setAssociatedObject(self, key, value, OBJC_ASSOCIATION_RETAIN);
    

    value would be retained until the association was broken. The association would be broken when self deallocs or when the association is changed with another objc_setAssociatedObject.

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

Sidebar

Related Questions

I haven't used the STL much before, but I started to on this huffman
Haven't touched Ruby for ages so this really puzzled me. Started up irb. Then
Haven't seen this feature anywhere else. I know that the 32nd bit is used
I haven't seen this on the Android docs. Is it safe to use this
I haven't used ARC yet other than to deal with it when it forces
I haven't used multithreading in Clojure at all so am unsure where to start.
I haven't been able to get this working and all of the sample code
I haven't seen this question anywhere else, I hope someone can help. I have
I haven't found any documentation on this or seen this done before, but is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.