PDFView setDocument: autorelease crash?
PDFView setDocument: autorelease crash?
- Subject: PDFView setDocument: autorelease crash?
- From: Keith Blount <email@hidden>
- Date: Sat, 10 Mar 2007 06:52:16 -0800 (PST)
Hello,
My app has a PDFView that is used to show different PDF files. I have an outline view that allows navigation of different types of file, and when a PDF file is selected, my PDFView is revealed in a tab view and I use -setDocument: exactly as recommended here:
http://developer.apple.com/documentation/GraphicsImaging/Conceptual/PDFKitGuide/PDFKit_Prog_Tasks/chapter_3_section_2.html
Here is my PDF loading code:
- (void)loadPDFDocumentFromFile:(NSString *)filePath
{
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
PDFDocument *pdfDoc = [[[PDFDocument alloc] initWithURL:fileURL] autorelease];
[pdfView setDocument:pdfDoc];
}
When other types of files are clicked on in the outline view, before revealing them in a different view in the tab view, I empty the PDF view like this:
// NOTE: to reset the PDFView properly, we have to go to the first page before setting the document to nil. If we don't
// do this, we get weird results when trying to go to a page after loading a new document. Weird, but it works...
[pdfView goToFirstPage:nil];
[pdfView setDocument:nil];
As far as I can see, all of this should work. However, users have been reporting various autorelease-type crashes related to PDF files, and today I finally managed to track the crash. It turns out that calling -setDocument over-releases the PDF document, for some reason. If I change my -loadPDFDocumentFromFile: method so that the PDFDocument does not get autoreleased, everything works fine with no crashes, as follows:
(void)loadPDFDocumentFromFile:(NSString *)filePath
{
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
PDFDocument *pdfDoc = [[PDFDocument alloc] initWithURL:fileURL];
[pdfView setDocument:pdfDoc];
}
The crashes go away, but this just does not seem right. The docs say that -setDocument: releases the current PDFDocument before loading the new one, so I would have thought that it would retain the newly loaded document, but these crashes seem to indicate, strangely, that it does not.
Is this a bug in PDFView, or have I missed something obvious?
Thanks in advance,
Keith
____________________________________________________________________________________
TV dinner still cooling?
Check out "Tonight's Picks" on Yahoo! TV.
http://tv.yahoo.com/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden