I'm working on several apps which are basically a PDF readers. Since iOS 6, apps started crashing because of being out of memory.
Our apps utilize PDF Reader, but a problem is not related to it. So far we found out:
1. leaking comes from CGContextDrawPDFPage
2. it is not there (or not so prominent) in iOS <6
3. leak does not occur on PDFS with no or small compression
To be specific: after opening a PDF with some compression, some memory is used. When PDF is closed, part of that memory is released. However, not all of it. You can easily get memory warning and then crash the app just by opening & closing PDF several times.
I've tried also PSPDF and although, it has advantages (speed) over PDF Reader, it's much more expensive and the same leaking is in there.
I have created very simple test project for PDF Reader and PSPDF Kit. (you just need to add some PDF to project)
Is there anything I can do to fix leaking in iOS 6 or am I doing something wrong and there is actually no leaking? My current approach is to wait for official fix.
I know the issue was discussed heavily here, but I believe my situation is a little bit different. (using ARC and tested libraries, leaking visible in simulator and on devices)
Thank you.
After a lot of trying, I've found out only two solutions. None of them is perfect, though.
1) Use Apple's QuickLook framework
- It is not leaking in iOS <6.0
- It is not leaking in iOS 6.0.
QuickLook runs in another process using XPC. However, that also means there is practically no customization. (see this question with a linked blog post)
2) Use FastPdfKit library
There seems to be no
CGContextDrawPDFPage
involved or maybe just some clever optimizations, but FastPdfKit is not leaking. Disadvantages are two - library is commercial and its rendering engine won't be shown to you even after you buy a license. You can use a free version with all the features, but there is a splash screen.As we're under a time pressure and can't afford neither to wait for official bugfix, nor leave our current features out, we've chosen FastPdfKit.
I wouldn't consider this to be a definite answer. The library suits our needs, might not yours. Also, it is a commercial product. If there is more straightforward solution, I'll gladly accept it.