• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Understanding objc_assign_strongCast
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Understanding objc_assign_strongCast


  • Subject: Understanding objc_assign_strongCast
  • From: David Elliott <email@hidden>
  • Date: Wed, 6 Feb 2008 18:27:32 -0500

Hi,

I am having a lot of trouble understanding exactly what the compiler- generated objc_assign_strongCast is supposed to do. The only documentation on this is one sentence in the Objective-C release notes.

From http://developer.apple.com/releasenotes/Cocoa/RN-ObjectiveC/
The compiler uses three "helper" functions for assignments of strong pointers to garbage collected memory into global memory (objc_assign_global), garbage collected heap memory (objc_assign_ivar), or into unknown memory (objc_assign_strongCast). For assignments of weak pointers it uses objc_assign_weak and for reads it uses objc_read_weak.


From what I can tell the compiler (Objective-C++ in my case) generates calls to objc_assign_strongCast whenever assigning an Objective-C pointer that is an i-var of a C++ class. I assume it would do something similar when assigning a field in a plain-old C struct.


But I have yet to find a single case where this keeps the object from being finalized! I initially thought it wasn't working when the C++ struct was located in the global data area. No problem, I followed Chris Hanson's advice and introduced CFRetain/CFRelease calls.

But now I've come across a case where I am certain the C++ object is allocated on the C++ heap (via a regular new operator, not overloaded). Even in this case, the objc_assign_strongCast which I am reasonably certain the compiler is generating (it shows in the output of gcc -S around where I expect it to) completely fails to keep the Objective-C object from being finalized. If that is not the purpose of objc_assign_strongCast then may I ask what is its purpose?

Note that the i-var in this case is a plain-old NSColor*. There is nothing fancy going on here. The only solution I have found is to again apply CFRetain/CFRelease appropriately.

So what gives?  What am I misunderstanding?

-Dave

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Searching for "whole word" in NSString
  • Next by Date: Re: Searching for "whole word" in NSString
  • Previous by thread: Re: NSCollectionView questions
  • Next by thread: re: Understanding objc_assign_strongCast
  • Index(es):
    • Date
    • Thread