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
+3 -1
View File
@@ -94,7 +94,9 @@
{ {
CGRect rect = [self getRect:context]; CGRect rect = [self getRect:context];
// add hit area // add hit area
self.hitArea = CGPathCreateWithRect(rect, nil); CGPathRef hitArea = CGPathCreateWithRect(rect, nil);
[self setHitArea:hitArea];
CGPathRelease(hitArea);
[self clip:context]; [self clip:context];
CGContextSaveGState(context); CGContextSaveGState(context);
+1 -1
View File
@@ -252,7 +252,7 @@
CGPathRelease(strokePath); CGPathRelease(strokePath);
} }
_hitArea = CGPathRetain(CGPathCreateCopy(hitArea)); _hitArea = CGPathRetain(CFAutorelease(CGPathCreateCopy(hitArea)));
CGPathRelease(hitArea); CGPathRelease(hitArea);
} }
+7 -2
View File
@@ -34,6 +34,11 @@
_cache = nil; _cache = nil;
} }
- (void)dealloc
{
CGPathRelease(_cache);
}
- (CGPathRef)getPath:(CGContextRef)context - (CGPathRef)getPath:(CGContextRef)context
{ {
if (_cache) { if (_cache) {
@@ -69,14 +74,14 @@
CGMutablePathRef linePath = [self getLinePath:line]; CGMutablePathRef linePath = [self getLinePath:line];
CGAffineTransform offset = CGAffineTransformMakeTranslation(0, _bezierTransformer ? 0 : CTFontGetSize(font) * 1.1); CGAffineTransform offset = CGAffineTransformMakeTranslation(0, _bezierTransformer ? 0 : CTFontGetSize(font) * 1.1);
CGPathAddPath(path, &offset, linePath); CGPathAddPath(path, &offset, linePath);
CGPathRelease(linePath);
_cache = CGPathRetain(CGPathCreateCopy(path)); _cache = CGPathRetain(CFAutorelease(CGPathCreateCopy(path)));
[self popGlyphContext]; [self popGlyphContext];
// clean up // clean up
CFRelease(attrString); CFRelease(attrString);
CFRelease(line); CFRelease(line);
CGPathRelease(linePath);
return (CGPathRef)CFAutorelease(path); return (CGPathRef)CFAutorelease(path);
} }
+7 -5
View File
@@ -29,15 +29,18 @@
[self clip:context]; [self clip:context];
CGContextSaveGState(context); CGContextSaveGState(context);
[self setupGlyphContext:context]; [self setupGlyphContext:context];
CGPathRef path = [self getPath:context];
CGPathRef path = [self getGroupPath:context];
CGAffineTransform transform = [self getAlignTransform:context path:path]; CGAffineTransform transform = [self getAlignTransform:context path:path];
CGContextConcatCTM(context, transform); CGContextConcatCTM(context, transform);
[self setHitArea:path];
[self renderGroupTo:context]; [self renderGroupTo:context];
[self releaseCachedPath]; [self releaseCachedPath];
CGContextRestoreGState(context); CGContextRestoreGState(context);
CGPathRef transformedPath = CGPathCreateCopyByTransformingPath(path, &transform);
[self setHitArea:transformedPath];
CGPathRelease(transformedPath);
} }
- (void)setupGlyphContext:(CGContextRef)context - (void)setupGlyphContext:(CGContextRef)context
@@ -71,10 +74,9 @@
[self setupGlyphContext:context]; [self setupGlyphContext:context];
CGPathRef groupPath = [self getGroupPath:context]; CGPathRef groupPath = [self getGroupPath:context];
CGAffineTransform transform = [self getAlignTransform:context path:groupPath]; CGAffineTransform transform = [self getAlignTransform:context path:groupPath];
CGPathRef transformedPath = CGPathCreateCopyByTransformingPath(groupPath, &transform);
[self releaseCachedPath]; [self releaseCachedPath];
return transformedPath; return (CGPathRef)CFAutorelease(CGPathCreateCopyByTransformingPath(groupPath, &transform));
} }
- (void)renderGroupTo:(CGContextRef)context - (void)renderGroupTo:(CGContextRef)context