What (tf) are the secrets behind PDF memory allocation (CGPDFDocumentRef)

后端 未结 1 653
我寻月下人不归
我寻月下人不归 2021-02-15 23:46

For a PDF reader I want to prepare a document by taking \'screenshots\' of each page and save them to disc. First approach is

CGPDFDocumentRef document = CGPDFDo         


        
1条回答
  •  面向向阳花
    2021-02-16 00:09

    CGPDFDocument caches pretty aggressively and you have very little control over that, apart from - as you've done - releasing the document and reloading it from disk.

    The reason you don't see a lot of allocations when you remove the CGContextDrawPDFPage call is that Quartz loads page resources lazily. When you just call CGPDFDocumentGetPage, all that happens is that it loads some basic metadata, like bounding boxes and annotations (very small in memory).

    Fonts, images, etc. are only loaded when you actually draw the page - but then they're retained for a relatively long time in an internal cache. This is meant to make rendering faster, because page resources are often shared between multiple pages. Also, it's fairly common to render a page multiple times (e.g. when zooming in). You'll notice that it's significantly faster to render a page the second time.

    0 讨论(0)
提交回复
热议问题