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

深入理解arc中有个疑问想请教 #14

Open
github1510 opened this issue Oct 10, 2020 · 2 comments
Open

深入理解arc中有个疑问想请教 #14

github1510 opened this issue Oct 10, 2020 · 2 comments

Comments

@github1510
Copy link

关于strong和weak的理解:
NSObject * temp = [[NSObject alloc] init];
__strong NSObject * temp = [[NSObject alloc] init];
这样有什么区别呢?

arc中没有strong和weak能不能正常运行?

@LeoMobileDeveloper
Copy link
Owner

LeoMobileDeveloper commented Oct 12, 2020

NSObject * temp = [[NSObject alloc] init];
__strong NSObject * temp = [[NSObject alloc] init];
这样有什么区别呢?

这两行没有任何区别,转换成汇编之后代码是一摸一样的。


arc中没有strong和weak能不能正常运行?

不能,默认变量就是strong的。arc本质上是retain/release/autorelease等函数,strong/weak是给编译器看的,编译器见到strong/weak会选择调用不同的arc函数

@github1510
Copy link
Author

我是不是可以这么理解:
在arc中,retain和strong是等同的,他们代表对象引用计数会增加,通过SideTable来实现;
weak则不一样,引用计数不会增加,通过弱引用表来实现

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

2 participants