I have a 30MB PDF file with 50 pages, which makes Aspose.Pdf.Document to consume a whopping 21.4 GB of memory.
memoryUsage.png (91.1 KB)
I’ve prepared a very simple project, which loads the document, iterates over the pages getting Contents.Count (i.e. no editing), then waits for a key-press (so that I could capture the memory usage at the end). Please note that you need to add a license file yourself, because the evaluation version limits the number of pages it can access.
(I’ll provide a link to it soon in my next post)
I’ve tried a few approaches to reduce the memory usage:
- Calling the GC
- Issuing a Document.FreeMemory()
- “Incremental saving” with Document.Save()
These function calls were made every page. To my surprise, none of them had any positive effect, and Document.Save() seemingly closed the underlying stream, so it even breaks the program.
My questions would be the following:
1.) What is the reason for this unproportionally large memory usage? The PDF file doesn’t seem to be unusually large, which makes the whole thing annoying.
2.) What can I do to make the processing of such files feasible on machines with less resources (say, “just” 16GB of RAM)?
3.) How the “incremental save” feature should be used?
Thanks in advance for your support!