Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
HuylensHu opened this issue Aug 18, 2015 · 2 comments
Open

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

HuylensHu opened this issue Aug 18, 2015 · 2 comments

Comments

@HuylensHu
Copy link

原文:
在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

@liuxuan30
Copy link

的确,a和b指向同一个内存地址,在b变nil时,a变nil,本身就不严谨;a和b指向同一个内存地址,不代表改变b就一定会改变内存地址的值,b = nil,难道a就变了么。

@juvham
Copy link

juvham commented Aug 19, 2015

不是这个意思吧,意思是对象本身被释放了,弱引用就指向nil 了,而不像 assign 会产生野指针

@ChenYilong ChenYilong changed the title 有一点说的很容易误导人 第8题 有一点说的很容易误导人 Aug 30, 2021
ChenYilong added a commit that referenced this issue Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants