- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
对于 PDF 阅读器,我想通过对每一页进行“截图”来准备文档并将其保存到光盘中。第一种方法是
CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((CFURLRef) someURL);
for (int i = 1; i<=pageCount; i++)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
CGPDFPageRef page = CGPDFDocumentGetPage(document, i);
...//getting + manipulating graphics context etc.
...
CGContextDrawPDFPage(context, page);
...
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
...//saving the image to disc
[pool drain];
}
CGPDFDocumentRelease(document);
这会导致在第一次运行循环(准备第一个文档)后似乎没有释放大量内存,但在其他运行中没有更多未释放的内存:
MEMORY BEFORE: 6 MB
MEMORY DURING 1ST DOC: 40 MB
MEMORY AFTER 1ST DOC: 25 MB
MEMORY DURING 2ND DOC: 40 MB
MEMORY AFTER 2ND DOC: 25 MB
....
把代码改成
for (int i = 1; i<=pageCount; i++)
{
CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((CFURLRef) someURL);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
CGPDFPageRef page = CGPDFDocumentGetPage(document, i);
...//getting + manipulating graphics context etc.
...
CGContextDrawPDFPage(context, page);
...
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
...//saving the image to disc
CGPDFDocumentRelease(document);
[pool drain];
}
将内存使用更改为
MEMORY BEFORE: 6 MB
MEMORY DURING 1ST DOC: 9 MB
MEMORY AFTER 1ST DOC: 7 MB
MEMORY DURING 2ND DOC: 9 MB
MEMORY AFTER 2ND DOC: 7 MB
....
但显然是性能上的倒退。
当我开始阅读 PDF(稍后,不同的线程)时,在第一种情况下不再分配内存(保持在 25 MB),而在第二种情况下,内存增加到 20 MB(从 7 开始)。
在这两种情况下,当我删除 CGContextDrawPDFPage(context, page);
在所有文档准备期间和之后,行内存(几乎)恒定为 6 MB。
谁能解释那里发生了什么?
最佳答案
CGPDFDocument 缓存非常积极,除了 - 正如你所做的那样 - 释放文档并从磁盘重新加载它之外,你几乎无法控制它。
删除 CGContextDrawPDFPage 调用时看不到很多分配的原因是 Quartz 延迟加载页面资源。当您只调用 CGPDFDocumentGetPage 时,所发生的只是它会加载一些基本的元数据,例如边界框和注释(内存非常小)。
字体、图像等仅在您实际绘制页面时加载 - 但随后它们会在内部缓存中保留相对较长的时间。这是为了加快渲染速度,因为页面资源通常在多个页面之间共享。此外,多次渲染页面(例如放大时)也很常见。您会注意到第二次渲染页面要快得多。
关于iphone - PDF 内存分配背后的 secret 是什么 (tf) (CGPDFDocumentRef),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4668772/
我知道之前有人问过这个问题,但我会更具体一些。 我有一个 CGPDFDocumentRef 文档,我想找到预告片,最好是 CGPDFDictionaryRef 的形式,这样我就可以查看它的 Encry
是否可以从 CGPDFDocumentRef 中检索文档的名称 最佳答案 “文档名称”是指文档文件名还是标题? 如果元数据中包含文档“标题”,则可以像这样检索它: char *titleKey
我正在构建一个报亭通用应用程序。当我下载一期杂志并打开它时,它运行正常,但是当我删除它,重新下载并打开它时,它会抛出以下错误: 2013-04-01 22:06:07.672 Magazine[143
我有一个问题,我希望有人能帮助我。 我将 PDF 文件下载到文档目录 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDi
我将我的 PDF 从 SQLite 数据库获取到一个 NSData 变量中。现在我可以从这个 NSData 创建 CGPDFDocumentRef 的选项是什么? 或者我有什么选择来创建这个 CGPD
处理 CGPDFDocumentRef 对象的适当方法是什么,以便可以将其添加到 NSArray 中,然后轻松地在其 CGPDFDocumentRef 中检索回来形式? 最佳答案 您可以轻松地将 CG
对于 PDF 阅读器,我想通过对每一页进行“截图”来准备文档并将其保存到光盘中。第一种方法是 CGPDFDocumentRef document = CGPDFDocumentCreateWithUR
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: how to fit pdf page in entire view 我可以毫无问题地显示 PDF,但是,在
我是一名优秀的程序员,十分优秀!