What is a non-weak reference to nulling,

In the OS X v10.11 beta release notes , I find the following:

NSNotificationCenter and NSDistributedNotificationCenter no longer send notifications to registered observers that may be released. If the observer can be saved as a link with a low level of zeroing, the basic storage stores the observer as a weak task of zeroing. Alternatively, if the object cannot be stored weakly (because it has its own save / free mechanism that prevents the RAM from storing the object weakly), the object is stored as a fuzzy zeroing reference . This means that observers are not required to refuse registration in the method of their release. [emphasis mine]

That doesn't make sense to me. If this is a non-weak link, is it not a strong link, then? Thus, the NSNotificationCenter will still be the owner, so the object will not be released (until it is unregistered manually), therefore, in this context, it makes no sense to talk about "zeroing".

If this refers to the __unsafe_unretained link, then the question is ... how then does NSNotificationCenter avoid messaging with zombies?

+6
source share
2 answers

The answer lies deeply in the objective-c runtime and how __weak variables really work. To explain, take a look at objc_weak.mm :

 id weak_read_no_lock(weak_table_t *weak_table, id *referrer_id) { ... if (! referent->ISA()->hasCustomRR()) { if (! referent->rootTryRetain()) { return nil; } } else { BOOL (*tryRetain)(objc_object *, SEL) = (BOOL(*)(objc_object *, SEL)) object_getMethodImplementation((id)referent, SEL_retainWeakReference); if ((IMP)tryRetain == _objc_msgForward) { return nil; } if (! (*tryRetain)(referent, SEL_retainWeakReference)) { return nil; } } return (id)referent; } 

As you can see, when the user -retain and -release user methods are used by the object, it does not guarantee that they support weak links at all (also note that you can use a completely different object for weak links of the object, although this is a topic at a different time) .

This is because weak links are cleared using objc_destructInstance , which calls objc_clearDeallocating , which calls weak_clear_no_lock .

Now objc_destructInstance NOT required to call custom object implementations, although most objects will call it.

Thus, the runtime allows you to implement the -allowsWeakReference (and retainWeakReference ) method to disable weak references to your object, in which case it is most likely to be nullified using the swizzling -dealloc object. Of course, these are all implementation details, so the NSNotificationCenter may have its own innovative way of doing something, but this is my best guess without trying to make out the NSNotificationCenter.

+4
source

Declaring a property as strong makes this property a strong reference. When declaring it weak, a nulling weak link is used. The unsafe_user modifier uses a loose weak link

In short: non-weak zeroing reference == unsafe_unretained refernce

Link:

https://mikeash.com/pyblog/friday-qa-2011-09-30-automatic-reference-counting.html http://www.jessesquires.com/UIKit-changes-in-iOS-9/

0
source

Source: https://habr.com/ru/post/988878/


All Articles