【IOS】ARC體驗感受記錄

本文固定鏈接:http://www.verydemo.com/demo_c134_i43204.html

1、不需要寫retainreleaseautorelease

2、某對象只要被strong指針指向則不會被銷燬,直到所有指向它的strong指針都指向別的地方;

3、默認情況下,所有實例變量和局部變量都是strong類型的;

4、weak類型的指針不持有對象,當所指對象失去所有指向它的strong指針時,該對象被銷燬,同時該weak指針自動指向nil;

6、記住:

    OSStatus status = SecItemCopyMatching((CFDictionaryRef) attributeQuery, (CFTypeRef *) &attributeResult); 

變更如下:

    CFTypeRef attri = (__bridge CFTypeRef)attributeResult;
    OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)attributeQuery, &attri);
10、dealloc只是處理一些必要處理的事情,如中止一個還沒有完成的網絡請求、刪除註冊的代理或通知.不需要release和[super dealloc];

11、使用@autoreleasepool{}塊代替NSAutoreleasePool;

12、屬性命名不以new開發;

13、不使用NSAllocateObject和NSDeallocateObject

14、

__bridge

簡單賦值,不會影響兩邊對象的retain count.

__bridge_transfer

賦值後釋放右邊的對象

__bridge_retained

賦值後也保留不釋放右邊的對象

15、IBOutlet最好都是weak型;

16、只要調用命名爲Create, Copy, Retain的Core Foundation函數,你都需要使用 CFBridgingRelease() 安全地將值傳遞給ARC;

17、ARC Block, 避免捕獲self,推薦採用如下代碼模式: 

__weak id weakSelf = self; 
block = ^() 
{ 
id strongSelf = weakSelf; 
if (strongSelf != nil) 
{ 
// do stuff with strongSelf 
} 
}

18、ARC單例

<pre …………………………………………………………………………
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章