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

Axel Howind commented on PDFBOX-5731:
-------------------------------------

[~lycheng] I updated the patch. Instead of doing a sweep each time a new 
COSName instance is created, I use a 
[Cleaner|https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ref/Cleaner.html]
 instance to automatically remove the key once the value is garbage collected. 
This works from Java 9 onwards and looks a lot cleaner (sic!) and easier to 
maintain than the reference queue.

I have tested that entries get removed, and while doing so have seen that 
apparently PDFDebugger has a memory leak because the WeakReferences never went 
stale (also when sweeping the map manually and even running System.gc() after 
loading different documents).

Please try and comment.

> org.apache.pdfbox.cos.COSName#nameMap There is a memory leak problem.
> ---------------------------------------------------------------------
>
>                 Key: PDFBOX-5731
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5731
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.30, 3.0.1 PDFBox
>            Reporter: liu
>            Priority: Major
>         Attachments: 
> attempted_fix_for_PDFBOX-5731__clear_out_unused_COSName_instances_automatically.patch,
>  
> attempted_fix_for_PDFBOX-5731__clear_out_unused_COSName_instances_automatically_2.patch,
>  image-2023-12-08-16-02-12-293.png, image-2023-12-13-17-04-22-073.png, 
> screenshot-1.png, screenshot-2.png, screenshot-3.png, screenshot-4.png, 
> screenshot-5.png
>
>
>  !image-2023-12-08-16-02-12-293.png! 
>  !screenshot-1.png! 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to