释放CGContextDrawPDFPage使用的内存

Ari*_*man 6 iphone cocoa-touch catiledlayer ios

当我用Instruments分析我的应用程序时,我发现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];
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试在它周围包装一个AutoReleasePool,但这似乎没有任何影响.屏幕截图是在TiledView(方法所属的视图)被释放后拍摄的.

我希望有人可以帮我减少内存使用量.

rai*_*ade 1

我也有类似的问题,

此行获取 pdf 页面

[self.superview.superview getPage]
Run Code Online (Sandbox Code Playgroud)

确保每次拉出一页时都重新打开 pdf,事实证明 CGPDFDocument 确实可以很好地处理内存。

例如。就像是

//release the current pdf doc
 if(self.pdfDocumentRef!=nil){
   CGPDFDocumentRelease(self.pdfDocumentRef);
 }
 //open it again
 self.pdfDocumentRef=CGPDFDocumentCreateWithURL(..your url..);
 //pull out a page
 CGPDFPageRef pg = CGPDFDocumentGetPage(self.pdfDocumentRef, pageIndex+1);
Run Code Online (Sandbox Code Playgroud)