嗨,我在我的应用程序中进行了大量计算,因为我的NSLog声明至少是 11 MB 的大应用程序的 2000 倍。我正在考虑从我的应用程序中删除它以提高性能。我想以正确的方式??
我使用下面的代码生成PDF但是导致内存泄漏可以有人帮忙吗?代码如下.
- (void)drawText:(NSString*)textToDraw inFrame:(CGRect)frameRect {
NSMutableAttributedString *string = [[[NSMutableAttributedString alloc]
initWithString:textToDraw] autorelease];
// make a few words bold
CTFontRef helveticaBold = CTFontCreateWithName(CFSTR("Helvetica-Bold"), 8.0, NULL);
[string addAttribute:(id)kCTFontAttributeName
value:(id)helveticaBold
range:NSMakeRange(0, [string length])];
// add some color.
if (_flag == 1) {
[string addAttribute:(id)kCTForegroundColorAttributeName
value:(id)[UIColor whiteColor].CGColor
range:NSMakeRange(0, [string length])];
} else {
[string addAttribute:(id)kCTForegroundColorAttributeName
value:(id)[UIColor blackColor].CGColor
range:NSMakeRange(0, [string length])];
}
// layout master
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)string);
CGMutablePathRef framePath = CGPathCreateMutable();
CGPathAddRect(framePath, NULL, frameRect);
// Get the frame that will do the rendering. …Run Code Online (Sandbox Code Playgroud)