Why variable with __weak qualifier retains an object?

♀尐吖头ヾ 提交于 2019-12-01 06:53:24

It seems that [[NSArray alloc] init] returns a "shared instance" of an empty NSArray:

NSArray *a = [[NSArray alloc] init];
NSArray *b = [[NSArray alloc] init];
NSLog(@"a &: %p", a);
NSLog(@"b &: %p", b);

Output:

    a &: 0x100103110
    b &: 0x100103110

This "shared instance" continues to exist even if your strong reference obj is gone, therefore the weak pointer is not set to nil.

Obviously, [[NSMutableArray alloc] init] cannot return a shared instance.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!