[ https://issues.apache.org/jira/browse/PDFBOX-4058?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16320783#comment-16320783 ]
Tilman Hausherr commented on PDFBOX-4058: ----------------------------------------- I ran the profiler and the only good news is that the weak cache does work somewhat, i.e. the size of the cache varies depending of tracing. (I noticed that I can render at 300 dpi when saving the paint image file. This suggests that gc works in parallel and the jdk doesn't wait for it to be done). This is confirmed by JDK-4802550: "It is not guaranteed that the garbage collector will always reclaim those objects before an OutOfMemoryError is thrown". I tried caching only patterns with an image below a certain size, but it turned out that this would also slow down rendering the file from PDFBOX-3688. Allowing to disable the cache would be the "desperate" solution but then I found out that adding an additional WeakReference level works too. The WeakHashMap javadoc suggests this too but for a different reason. > High memory consumption when extracting image from PDF file > ----------------------------------------------------------- > > Key: PDFBOX-4058 > URL: https://issues.apache.org/jira/browse/PDFBOX-4058 > Project: PDFBox > Issue Type: Bug > Components: Rendering > Affects Versions: 2.0.5, 2.0.6, 2.0.7, 2.0.8 > Environment: windows 10 / Linux > Reporter: Bjorn Misseghers > Labels: regression > Attachments: HighMemoryFootprint.pdf > > > When rendering an image at 300 dpi from the included PDF, my java process > uses a huge amount of memory. > The document is only 45 Kb in size and contains 2 pages, my JVM is unable to > extract even 1 page with 3G of memory. Setting Xmx to 4G works but is not the > solution I want. > The error occurs when calling PDFRenderer.renderImageWithDPI() > I already tried tweaking the memory usage in my application to use a scratch > file while loading the document as well as avoiding caching of XObjects as > described here: https://pdfbox.apache.org/2.0/faq.html#outofmemoryerror > These didn't work. > The issue can be reproduced using the pdfbox-app utility: > java -Xmx3G -jar pdfbox-app-2.0.8.jar PDFToImage > HighMemoryFootprint.pdf -dpi 300 -color RGB -page 1 > What can not be changed? > * 300 dpi will not be decreased. > * Max Java memory will not be increased: 3GB is ridiculous for a 45kb PDF > file. -- This message was sent by Atlassian JIRA (v6.4.14#64029) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org