代码如下
- (void)testWeak{
__weak id weaSelf = self;
}
转成汇编
"-[A testWeak]": ; @"\01-[A testWeak]"
sub sp, sp, #48 ; =48
stp x29, x30, [sp, #32] ; 16-byte Folded Spill
add x29, sp, #32 ; =32
stur x0, [x29, #-8]
str x1, [sp, #16]
ldur x1, [x29, #-8]
add x8, sp, #8 ; =8
mov x0, x8
str x8, [sp] ; 8-byte Folded Spill
bl _objc_initWeak
ldr x8, [sp] ; 8-byte Folded Reload
mov x0, x8
bl _objc_destroyWeak
ldp x29, x30, [sp, #32] ; 16-byte Folded Reload
add sp, sp, #48 ; =48
ret
调用了 _objc_initWeak 和 _objc_destroyWeak 函数
去runtime里去找对应的实现
id
objc_initWeak(id *location, id newObj)
{
if (!newObj) {
*location = nil;
return nil;
}
return storeWeak<DontHaveOld, DoHaveNew, DoCrashIfDeallocating>
(location, (objc_object*)newObj);
}
void
objc_destroyWeak(id *location)
{
(void)storeWeak<DoHaveOld, DontHaveNew, DontCrashIfDeallocating>
(location, nil);
}
未完待续~
网友评论