作者:
uranusjr (â†é€™äººæ˜¯è¶…級笨蛋)
2014-04-16 13:53:41※ 引述《darktt (小朱)》之銘言:
→ Blueshiva:RefCount降到0也不會馬上刪除,必須等autorelease pool 04/16 11:42
→ Blueshiva:要刪除的時候才會一起檢查,一起刪除 04/16 11:42
實際上 Foundation 裡面怎麼做我是不知道啦, 但這是 Cocotron 的源碼
http://d.pr/B3bo
-(oneway void)release {
if(NSDecrementExtraRefCountWasZero(self))
[self dealloc];
}
這是蘋果開源的 Objective-C Runtime 源碼
http://www.opensource.apple.com/source/objc4/objc4-532/runtime/NSObject.mm
- (oneway void)release
__attribute__((aligned(16)))
{
// tagged pointer check is inside _objc_rootReleaseWasZero().
if (_objc_rootReleaseWasZero(self) == false) {
return;
}
[self dealloc];
}
如果 release 之後 ref count 是 0 就會直接呼叫 dealloc 進入自爆程序了
沒記錯的話, 蘋果的文件也是說 ref count 一旦降到 0 就會立刻毀滅