Usually weak
references are used to avoid retain cycles in the application object graph. I understand that part. Now I would like to go a step further and understand how they work under the hood.
Searching a bit, I've read that when I'm using the __weak
qualifier, the variable associated with that qualifier is registered in an autorelease pool, but what does this mean? Why is the object registered in the pool? What type of pool is used? Is it 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 that 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 by myStrongObj
? If possible, I'd like to know what the compiler's code looks like?