I've been struggling for ages trying to make a working PDF reader for iPhone/iPad, but the thing just won't stop eating memory. It seems that all the pages drawn with CGContextDrawPDFPage are cached internally and never released.
I'm not the only one with this problem: http://lists.apple.com/archives/quartz-dev/2010/Apr/msg00025.html
http://web.archiveorange.com/archive/v/SEb6acvPicMB2NdIjEd3
One response from the first thread:
If this is what I think it is, it isn't a leak but rather a cache. Instead of retaining the PDF document between calls, try creating the document, getting and drawing the page, then releasing the document when your done.
I've tried it, and it solves the problem, but it's too damn slow. Whereas doing it in the "normal" way (i.e. without loading/releasing CGPDFDocument for every draw) works good and reasonably fast until I reach the 4th or 5th page of the document and it crashes.
I've googled this problem for ages: everybody has the same problem but apparently nobody got it working. The only samples I found load a one-page PDF, so obviously everything works fine until you load a document with multiple pages (and of course if the thing has images in it, it crashes even earlier). This is driving me crazy.
So the question is: how exactly do you handle PDF drawing with CGPDF in your app? Any help would be greatly appreciated. Thanks.