淺談IOS內存優化經驗
作者:佚名
本文介紹的是淺談IOS內存優化經驗,主要介紹的是IOS的內存,我們來看詳細內容。
淺談IOS內存優化經驗是本文要介紹的內容,詳細的講解了IOS的內存優化方案,不多說,我們先來看詳細內容。
首先最最重要的還是確保每個retain,copy,delloc都帶有一個release
1.凡事有CT..Create..的要用CTRelease(myObject)釋放; CF等也同樣道理
2.下面的return前也沒有釋放
- CTParagraphStyleRef paragraphStyle=CTParagraphStyleCreate(paragraphStyle_settings,
- sizeof(paragraphStyle_settings) / sizeof(paragraphStyle_settings[0]));
- if(...)
- {
- <SPAN style="WHITE-SPACE: pre"> </SPAN>return; //這里會溢出
- }
- CTRelease(paragraphStyle);
- CTParagraphStyleRef paragraphStyle=CTParagraphStyleCreate(paragraphStyle_settings,
- sizeof(paragraphStyle_settings) / sizeof(paragraphStyle_settings[0]));
- if(...)
- {
- return; //這里會溢出
- }
- CTRelease(paragraphStyle);
3.有時NSMutableArray mutableCopy也會溢出
- NSMutableArray *mutableRecents = [NSMutableArray arrayWithArray:recentSearches];
- //NSMutableArray *mutableRecents = [recentSearches mutableCopy]; 這里內存會溢出
- [mutableRecents removeObject:searchString];
- NSMutableArray *mutableRecents = [NSMutableArray arrayWithArray:recentSearches];
- //NSMutableArray *mutableRecents = [recentSearches mutableCopy]; 這里內存會溢出
- [mutableRecents removeObject:searchString];
4.dealloc里面的內存溢出大部分由init或initWithFrame不正當的初始化引起
5:先在Instrument下用模擬器檢查內存溢出,再用Instrument連真機檢查.
小結:淺談IOS內存優化經驗的內容介紹完了,希望本文對你有所幫助!
責任編輯:zhaolei
來源:
互聯網