Fix memory leaks

This commit is contained in:
Horcrux
2017-01-11 19:31:42 +08:00
parent 6e81ecf147
commit dcc39c4b67
4 changed files with 18 additions and 9 deletions
+7 -2
View File
@@ -34,6 +34,11 @@
_cache = nil;
}
- (void)dealloc
{
CGPathRelease(_cache);
}
- (CGPathRef)getPath:(CGContextRef)context
{
if (_cache) {
@@ -69,14 +74,14 @@
CGMutablePathRef linePath = [self getLinePath:line];
CGAffineTransform offset = CGAffineTransformMakeTranslation(0, _bezierTransformer ? 0 : CTFontGetSize(font) * 1.1);
CGPathAddPath(path, &offset, linePath);
CGPathRelease(linePath);
_cache = CGPathRetain(CGPathCreateCopy(path));
_cache = CGPathRetain(CFAutorelease(CGPathCreateCopy(path)));
[self popGlyphContext];
// clean up
CFRelease(attrString);
CFRelease(line);
CGPathRelease(linePath);
return (CGPathRef)CFAutorelease(path);
}
+7 -5
View File
@@ -29,15 +29,18 @@
[self clip:context];
CGContextSaveGState(context);
[self setupGlyphContext:context];
CGPathRef path = [self getPath:context];
CGPathRef path = [self getGroupPath:context];
CGAffineTransform transform = [self getAlignTransform:context path:path];
CGContextConcatCTM(context, transform);
[self setHitArea:path];
[self renderGroupTo:context];
[self releaseCachedPath];
CGContextRestoreGState(context);
CGPathRef transformedPath = CGPathCreateCopyByTransformingPath(path, &transform);
[self setHitArea:transformedPath];
CGPathRelease(transformedPath);
}
- (void)setupGlyphContext:(CGContextRef)context
@@ -71,10 +74,9 @@
[self setupGlyphContext:context];
CGPathRef groupPath = [self getGroupPath:context];
CGAffineTransform transform = [self getAlignTransform:context path:groupPath];
CGPathRef transformedPath = CGPathCreateCopyByTransformingPath(groupPath, &transform);
[self releaseCachedPath];
return transformedPath;
return (CGPathRef)CFAutorelease(CGPathCreateCopyByTransformingPath(groupPath, &transform));
}
- (void)renderGroupTo:(CGContextRef)context