本文并非最终版本,如有更新或更正会第一时间置顶,联系方式详见文末
如果觉得本文内容过长,请前往本人 “简书”
通过 Product -> Analyze 来进行静态分析
|
使用Path 对象时的内存管理问题:
1、凡是遇到 retain 、 copy 、 create 函数创建出的对象, 使用完后都需要进行 release,否则将导致内存泄露
2、但是CGPathCreateMutable( )不是 OC 方法, 所以不是调用某个对象的 release方法
3、CGXxxxxCreate 对应的就有 CGXxxxxRelease。
4、通过 CFRelease(任何类型);可以释放任何类型。
|
示例代码:
- (void)drawRect:(CGRect)rect
{
// 1.获取上下文(layer)
CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.拼接路径
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, , );
CGPathAddLineToPoint(path, NULL, , ); // 3.把路径添加到上下文当中
CGContextAddPath(ctx, path); // 4.渲染
CGContextStrokePath(ctx); // 释放
CGPathRelease(path); //方法1
CFRelease(path); //方法2
}