CGContextDrawPDFPage崩溃而没有产生内存警告 [英] CGContextDrawPDFPage crashing without ever producing a memory warning

查看:273
本文介绍了CGContextDrawPDFPage崩溃而没有产生内存警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试渲染一个带有一些批注的PDF页面(以便通过电子邮件发送),并且大多数情况下都可以正常工作.

但是,尤其是使用 PDF 时,它似乎崩溃了每次在CGContextDrawPDFPage上调用第一页.我已添加

CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);

作为 CGContextDrawPDFPage占用大量内存的建议但这似乎并不能解决我的问题.

我通过探查器运行此命令以查看发生了什么,它慢慢开始分配一堆内存,直到最终它达到512MB的活动字节并死亡.

奇怪的是,当我将其渲染到图像(用于在设备上显示)上下文时,它似乎可以正常工作,但是当我将其渲染到PDF上下文(用于通过电子邮件发送注释)时,它会中断.我尝试过的所有其他PDF在这两种情况下都可以正常工作.

我希望编写PDF查看器/注释器的人可以对其进行测试,看看该文档是否对他们有用,如果可以,请给我一些有关他们正在减少CGContextDrawPDFPage的内存分配的提示. /p>

我查看的另一个资源是很棒的解决方案

您是否在主线程上构建PDF?如果是这样,您可能不会收到内存警告,因为在执行过程中您已阻止了该信号,因为运行循环永远没有机会向您发送消息.

I'm trying to render a PDF page with some annotations on it (to email), and most of the time this works fine.

However, with this PDF in particular it seems to crash every time on the call to CGContextDrawPDFPage for the first page. I have added

CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);

as a recommendation from CGContextDrawPDFPage taking up large amounts of memory but that did not seem to solve my issue.

I ran this through the profiler to see what was going on, and it slowly started allocating a bunch of memory until finally it hit 512MB of live bytes and died.

The strange thing is that when I render this to an image (for display on the device) context it seems to work fine but when I render it to a PDF context (for emailing with annotations), it breaks. All of the other PDFs I've tried work fine in both cases.

I was hoping that someone who's written a PDF viewer/annotator could test this out and see if this document works for them and if so, give me some tips about what they're doing to reduce the memory allocations of CGContextDrawPDFPage.

Another resource I looked at was this great SO Question.

Edit (more info on the crash):

90% of the time the crash doesn't actually show up, the gdb line displays but the app goes away and the stack trace doesn't show. (It says paused but there is no thread display). One time I saw it was an exc_bad_access and it showed this in the log:

malloc: *** mmap(size=16777216) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

解决方案

Are you constructing the PDF on the main thread? If so, you may not receive the memory warning because you've blocked the signal while in execution, since the run loop never has a chance to dispatch the message to you.

这篇关于CGContextDrawPDFPage崩溃而没有产生内存警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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