Closed mlilback closed 12 years ago
It's possible to detect whether an object supports native ZWR using the allowsWeakReference
message. See the weak_register_no_lock
function here: http://opensource.apple.com/source/objc4/objc4-493.9/runtime/objc-weak.mm
Unfortunately, this is a private API and so probably shouldn't be relied upon. I think that the best approach here would be to write a separate little program that goes through all of the classes in the frameworks and fetches a list of ones that don't allow ZWR. That list could then be baked into MAZWR and used to decide whether to use native weak references or not. The list will only shrink with time, so it should be safe to do this.
This is now done, using the above plan with the twist of using a table of SHA1 hashes instead of a table of class names to avoid falling afoul of app reviewers and private API.
On Snow Leopard, MAZeroingWeakRef worked with every class I tried. On Lion, it doesn't work with subclasses of NSViewController, which do not support ZWRs since NSViewController overrides retain and/or release.
I'm not sure how to check to see if a class supports ZWR, but MAZWR should fallback to the old mechanism when the runtime version of ZWR won't work.