ChenYilong / ChenYilong/iOSInterviewQuestions

第8题 有一点说的很容易误导人

Open
#6 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Swift
Stars
9.5k
Forks
2.8k
PR merge metrics
No merged PRs in 30d

Description

原文:
在b非nil时,a和b指向同一个内存地址,在b变nil时,a变nil。此时向a发送消息不会崩溃:在Objective-C中向nil发送消息是安全的。
理解:
__weak someType *a = someInstance;
__weak someType *b = someInstance;
b = nil;
此时a是不会变nil的,
即使执行someInstance = nil;
假如在这之前还有 someType *strongInstance = someInstance;
a也不会变nil,只有当someInstance的引用计数变为0时,那些weak指向它的才会变nil

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.