當我使用Instruments分析我的應用程序時,我發現CGContextDrawPDFPage分配的數據不會立即釋放。由於我的程序收到很多「內存警告」,我想釋放盡可能多的內存,但我不知道如何釋放這些內存。取消分配CGContextDrawPDFPage使用的內存
正如你可以看到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(方法所屬的視圖)被釋放之後拍攝屏幕截圖。
我希望有人能幫助我減少內存使用量。