CGPDF iPhone / iPad内存问题 [英] CGPDF iPhone/iPad memory problems

查看:80
本文介绍了CGPDF iPhone / iPad内存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力为iPhone / iPad制作一个可用的PDF阅读器,但事情并不止于此。似乎用CGContextDrawPDFPage绘制的所有页面都在内部缓存,从未发布过。

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.

我不是唯一遇到此问题的人: http://lists.apple.com/archives/quartz-dev/2010/Apr/msg00025.html

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:


如果这是我认为的话是,它不是泄漏而是缓存。不是在调用之间保留PDF文档,而是尝试创建文档,获取和绘制页面,然后在完成后释放文档。

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.

我试过了,它解决了这个问题,但它太慢了。虽然以正常的方式进行(即没有为每次抽奖加载/发布CGPDFDocument),但是在我到达文档的第4页或第5页并且崩溃之前,工作良好且合理地快。

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.

我已经搜索了这个问题多年了:每个人都有同样的问题,但显然没有人得到它的工作。我发现的唯一样本加载了一页PDF,所以显然一切都正常,直到您加载一个包含多个页面的文档(当然,如果事物中有图像,它甚至更早崩溃)。这真让我抓狂。

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.

所以问题是:你在应用程序中如何使用CGPDF处理PDF绘图?任何帮助将不胜感激。谢谢。

So the question is: how exactly do you handle PDF drawing with CGPDF in your app? Any help would be greatly appreciated. Thanks.

推荐答案

我目前的企业项目基于PDF阅读器。我没有发布CGPDFDocument,我可以翻阅14页apple pdf,应用程序最大值为30mb。我不能给你代码,但我可以指出你正确的方向。

My current Enterprise Project is based round a PDF reader. I don't release CGPDFDocument and I can page through a 14 page apple pdf with the app maxing at 30mb. I cant give you code but i can point you in the right direction.

我在这里开始了一个类似的线程:用于iPhone / iPad / iOs的快速和精益PDF阅读器 - 提示和提示?

I started a similar thread here: Fast and Lean PDF Viewer for iPhone / iPad / iOs - tips and hints?

一些提示:

- 尽可能将任何媒体保存到磁盘。

-Save any media to disk when you can.

- 如果在TiledLayers上渲染,则使用更大的tileSizes

-Use larger tileSizes if rendering on TiledLayers

- 表示图像渲染速度比CGPDFPageRef快

-Note that images will render faster than a CGPDFPageRef

- 使用NSOperations提前准备页面

时间。

-Use NSOperations to prepare pages ahead
of time.

- 回收页面对象

- 在您不需要时立即关闭任何打开的上下文

-Close any open Contexts as soon as you don't need them

- 收到内存警告发布并重新加载DocRef

-on receiving a memory warnings release and reload the DocRef

这篇关于CGPDF iPhone / iPad内存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆