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)