简体   繁体   English

CGContextDrawPDFPage崩溃而没有产生内存警告

[英]CGContextDrawPDFPage crashing without ever producing a memory warning

I'm trying to render a PDF page with some annotations on it (to email), and most of the time this works fine. 我正在尝试渲染带有一些批注的PDF页面(通过电子邮件发送),并且大多数情况下都可以正常工作。

However, with this PDF in particular it seems to crash every time on the call to CGContextDrawPDFPage for the first page. 但是,尤其是对于此PDF ,似乎在每次调用CGContextDrawPDFPage的第一页时都会崩溃。 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. 作为CGContextDrawPDFPage的建议,它占用了大量内存,但这似乎无法解决我的问题。

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. 我通过探查器来运行它,以查看发生了什么,它慢慢开始分配一堆内存,直到最终它达到了512MB的活动字节并死亡。 仪器中分析的内存分配

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. 奇怪的是,当我将其渲染到图像上下文(以便在设备上显示)时,它似乎可以正常工作,但是当我将其渲染到PDF上下文时(用于通过电子邮件发送注释)时,它会中断。 All of the other PDFs I've tried work fine in both cases. 我尝试过的所有其他PDF在这两种情况下都能正常工作。

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. 我希望编写PDF查看器/注释器的人可以对其进行测试,看看该文档是否对他们有用,如果可以,请给我一些有关他们正在减少CGContextDrawPDFPage的内存分配的建议。

Another resource I looked at was this great SO Question. 我查看的另一个资源是这个很棒的SO问题。

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. 90%的崩溃实际上没有显示出来,但gdb行显示了,但是应用程序消失了,堆栈跟踪也没有显示。 (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: 有一次我看到它是一个exc_bad_access,它在日志中显示了这个:

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

删除xcode中的异常断点,它可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM