views:

174

answers:

1

I've been doing research because my pdf viewer app keeps crashing around page 4/5 because of a memory leek that happens every time you turn a page...

It turns out that apple have a bug.

see here: https://devforums.apple.com/message/9077#9077

from what I understand you have to release & retain the pdf document every time you change page.

but I can't get it to work (this code is in a subclass of 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

my pdf is got here in a 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;}

I can't find anything on google and I've been reading the documentation all day.

Any ideas?

A: 

Yeah. Bug. You will have to open/close the complete document when drawing a page. Sucks.

(I think this is fixed in 3.2.x)

St3fan
how???? i can't see any information any where
im going to download sdk 4.0 i will tell you if the bug is fixed
Wow - is this a recent post? But you might just be right. Afaik there are no Create:s etc that would indicate ownership of a page when drawing it - I guess all memory when drawing page by page is "hung on" to the original document reference (which indeed includes the word Create, CGPDFDocumentCreateWithURL, which would indicate ownership)? In any way, how would you ever be able to free the memory of no longer needed pages if you never received the sole ownership of them?
Jonny