1.2 Quartz 2D memory management, quartz2d

Source: Internet
Author: User

1.2 Quartz 2D memory management, quartz2d

Use Product-> Analyze for Static Analysis  
  • You can use the Quartz 2D function to specify the retain and release objects. For example, if a CGColorSpace object is created, the CGColorSpaceRetain and CGColorSpaceRelease functions are used to retain and release objects.
  • You can also use the CFRetain and CFRelease of the Core Foundation. Note that NULL values cannot be passed to these functions.
Memory management problems when using the Path object:
1. All objects created by the retain, copy, and create functions must be release after use. Otherwise, memory leakage will occur. 2. However, CGPathCreateMutable () is not an OC method, therefore, CGXxxxxRelease is not used to call the release method 3 and CGXxxxxCreate of an object. 4. CFRelease (any type); can release any type.
Sample Code:
1-(void) drawRect :( CGRect) rect 2 {3 // 1. obtain the context (layer) 4 CGContextRef ctx = UIGraphicsGetCurrentContext (); 5 6 // 2. splicing path 7 CGMutablePathRef path = CGPathCreateMutable (); 8 CGPathMoveToPoint (path, NULL, 50, 50); 9 CGPathAddLineToPoint (path, NULL, 100,100); 10 11 // 3. add the path to the context 12 CGContextAddPath (ctx, path); 13 14 // 4. rendering 15 CGContextStrokePath (ctx); 16 17 // release 18 CGPathRelease (path); // method 119 CFRelease (path); // method 220}

 

If you have any questions, please send an e-mail to shorfng@126.com to contact me. By: Loto)

Related Article

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.