[ 
https://issues.apache.org/jira/browse/PDFBOX-351?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12644175#action_12644175
 ] 

Chris Nash commented on PDFBOX-351:
-----------------------------------

I see the same problem here and eventually run the JVM out of memory because of 
it when called from within a server process. However I'd prefer a better fix 
than having to periodically call a clearResources method on a class that I do 
not directly use.

Could we at the very least use a WeakHashMap instead? That will at least allow 
the entries to be automatically garbage collected when necessary.

Is there any particular reason the hash map is necessary at all? COSName does 
implement equals/hashCode/compareTo so surely doesn't need to guarantee a 
single instance of every name. I can't see any reason anywhere why it's 
required that the same name is always the same instance of COSName. In fact, if 
I call the clearResources method above while I'm processing another document on 
another thread, the names will end up getting recreated anyway.

Returning a new COSName from getPDFName() every time should perform better on a 
modern JVM in any case - it'll cost about as much to allocate the object as it 
does to look it up in the map, and temporary COSName's will get deallocated 
pretty much for free.

> patch to reclaim resources from COSName
> ---------------------------------------
>
>                 Key: PDFBOX-351
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-351
>             Project: PDFBox
>          Issue Type: Improvement
>            Reporter: Jukka Zitting
>
> [Issue from SourceForge]
> http://sourceforge.net/tracker/index.php?func=detail&aid=1939690&group_id=78314&atid=552834
> Similar to PDFont, COSName caches a lot of resources that can hurt a
> long-running process. This patch adds a clearResources method to COSName,
> similar in intent to the one in PDFont. [ flester at gmail dot com ]
> http://sourceforge.net/tracker/download.php?group_id=78314&atid=552834&file_id=274060&aid=1939690

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to