ページをめくるたびにメモリ リークが発生し、pdf ビューアー アプリがページ 4/5 あたりでクラッシュし続けるため、調査を行っています。
Apple にバグがあることが判明しました。
ここを参照してください: https://devforums.apple.com/message/9077#9077
私が理解していることから、ページを変更するたびにpdfドキュメントをリリースして保持する必要があります。
私はそれを動作させることができません (このコードは UIView のサブクラスにあります):
- (void) drawInContext: (CGContextRef) ctx {
CGPDFDocumentRelease(__pdfDoc);
CGContextSetRGBFillColor( ctx, 1.0, 1.0, 1.0, 1.0 );
CGContextFillRect( ctx, CGContextGetClipBoundingBox( ctx ));
CGContextTranslateCTM( ctx, 0.0, self.bounds.size.height );
CGContextScaleCTM( ctx, 1.0, -1.0 );
CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(pdfPage, kCGPDFCropBox, self.bounds, 0, true));
CGContextDrawPDFPage( ctx, pdfPage );NSLog(@"DONE!");
CGPDFDocumentRetain(__pdfDoc);}
@end
私のpdfはここでviewControllerで開かれます:
- (CGPDFPageRef) pdfPage: (NSInteger) index {
if( ! __pdfDoc ) {
__pdfDoc = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"mybook" ofType:@"pdf"]]);}
if( __pdfDoc ) {
size_t pdfPageCount = CGPDFDocumentGetNumberOfPages( __pdfDoc );
index++;
if( index < 1 )
index = 1;
if( index > pdfPageCount )
index = pdfPageCount;
CGPDFPageRef page = CGPDFDocumentGetPage( __pdfDoc, index );
return page;}
return nil;}
グーグルで何も見つからず、一日中ドキュメントを読んでいます。