What happens to __weak qualified variables under the hood?

weakLinks are commonly used to avoid storing loops in the graph of application objects. I understand this part. Now I would like to take another step and understand how they work under the hood.

Searching a bit, I read that when I use the qualifier __weak, the variable associated with this qualifier is registered in the auto-detection pool, but what does it mean? Why is the object registered in the pool? What type of pool is used? Is this the main pool or some other specially created one?

When I use this code:

id _weak myWeakObj = [[NSObject alloc] init];

the compiler gives me a warning, which I can fix with:

id _strong myStrongObj =  [[NSObject alloc] init];
id _weak myWeakObj = myStrongObj;

So, based on the previous question, what happens to the object referenced myStrongObj? If possible, I would like to know what the compiler code looks like?

+3
source share
1 answer

Below is your friend:

And also the source for the Objective-C runtime:

In particular, see:

objc_initWeak objc_destroyWeak 1- , , " ". weak_register_no_lock weak_unregister_no_lock .

, , : -).

+5

All Articles