IOS memory optimization experience

Source: Internet
Author: User

DiscussionIOS Memory OptimizationExperience is the content to be introduced in this article.IOSOfMemory OptimizationSolution. Let's look at the details first.

First, make sure that each retain, copy, and delloc has a release

1. CT... Create... is used to release CTRelease (myObject); CF is also true.

2. The following return is not released either.

 
 
  1. CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate (paragraphStyle_settings,
  2. Sizeof (paragraphStyle_settings)/sizeof (paragraphStyle_settings [0]);
  3. If (...)
  4. {
  5. <SPAN style = "WHITE-SPACE: pre"> </SPAN> return; // Overflow
  6. }
  7. CTRelease (paragraphStyle );
  8. CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate (paragraphStyle_settings,
  9. Sizeof (paragraphStyle_settings)/sizeof (paragraphStyle_settings [0]);
  10. If (...)
  11. {
  12. Return; // Overflow
  13. }
  14. CTRelease (paragraphStyle );

3. Sometimes NSMutableArray mutableCopy overflows.

 
 
  1. NSMutableArray * mutableRecents = [NSMutableArray arrayWithArray: recentSearches];
  2. // NSMutableArray * mutableRecents = [recentSearches mutableCopy]; memory overflow
  3. [MutableRecents removeObject: searchString];
  4. NSMutableArray * mutableRecents = [NSMutableArray arrayWithArray: recentSearches];
  5. // NSMutableArray * mutableRecents = [recentSearches mutableCopy]; memory overflow
  6. [MutableRecents removeObject: searchString];

4. Most memory overflow in dealloc is caused by improper initialization of init or initWithFrame.

5: Check the memory overflow with the simulator under the Instrument, and then use the Instrument to connect the real machine.

Summary:IOS Memory OptimizationI hope this article will help you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.