浅谈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内存优化经验的内容介绍完了,希望本文对你有所帮助!