Will the Objective-C runtime version keep associative links for the user?

When some of these codes:

objc_setAssociatedObject ( obj, &key, val, OBJC_ASSOCIATION_RETAIN ); 

I need to call related

 objc_setAssociatedObject ( obj, &key, nil, OBJC_ASSOCIATION_RETAIN ); 

to free the stored value? Does Objective-C automatically distribute associative links in dealloc or dealloc ?

+7
source share
1 answer

Related objects will be freed when the parent is freed. See the documentation here , specifically this example:

At point 1, the overview line is still valid because the OBJC_ASSOCIATION_RETAIN policy indicates that the array saves the associated object. However, when the array is freed, (at point 2), overview freed and therefore also freed in this case.

+14
source

All Articles