当我使用Instruments分析我的应用程序时,我发现由CGContextDrawPDFPage分配的数据不会立即释放。由于我的程序接收到大量“内存警告”,我希望尽可能释放更多的内存,但我不知道如何释放这些内存。
正如您在http://twitpic.com/473e89/full中看到的,似乎与此代码有关。
我已经尝试使用AutoReleasePool来包裹它,但似乎没有任何影响。截图是在TiledView(该方法所属的视图)被释放后拍摄的。 我希望有人能帮助我减少内存使用。
正如您在http://twitpic.com/473e89/full中看到的,似乎与此代码有关。
-(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx{
NSAutoreleasePool * tiledViewPool = [[NSAutoreleasePool alloc] init];
CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(ctx, CGContextGetClipBoundingBox(ctx));
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform([self.superview.superview getPage],kCGPDFMediaBox,tiledLayer.bounds, 0, true);
CGContextSaveGState (ctx);
CGContextTranslateCTM(ctx, 0.0, tiledLayer.bounds.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextConcatCTM (ctx, pdfTransform);
CGContextClipToRect (ctx, CGPDFPageGetBoxRect([self.superview.superview getPage],kCGPDFMediaBox));
CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh);
CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);
CGContextDrawPDFPage(ctx,[self.superview.superview getPage]);
CGContextRestoreGState (ctx);
UIGraphicsEndPDFContext();
[tiledViewPool drain];
}
我已经尝试使用AutoReleasePool来包裹它,但似乎没有任何影响。截图是在TiledView(该方法所属的视图)被释放后拍摄的。 我希望有人能帮助我减少内存使用。