可以使用NSHashTable存储weak指针
NSObject *obj = [[NSObject alloc] init];
__weak NSObject *weakobj1 = obj;
NSHashTable *table = [NSHashTable weakObjectsHashTable];
[table addObject:weakobj1];
image.png
NSObject *obj = [[NSObject alloc] init];
__weak NSObject *weakobj1 = obj;
NSHashTable *table = [NSHashTable weakObjectsHashTable];
[table addObject:weakobj1];
weakobj1 = nil;
obj = nil;
image.png
网友评论