[ https://issues.apache.org/jira/browse/PDFBOX-5731?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17796711#comment-17796711 ]
Andreas Lehmkühler edited comment on PDFBOX-5731 at 12/21/23 4:36 PM: ---------------------------------------------------------------------- [~lycheng] I have created a patch for PDFBox 3. I use a cleanup thread instead, to prevent the memory leak I mentioned earlier. Also the locking should not be on the queue but on nameMap to prevent a race condition that could lead to another memory leak. I am referring to this piece from your proposed code: {code:java} public static void removeNameMapKey() { Reference<? extends COSName> ref; while ((ref = queue.poll()) != null) { synchronized (queue) { Entry entry = (Entry) ref; nameMap.remove(entry.getName()); } } } {code} The output I get from the test code looks good: {noformat} 0, size=570 1000000, size=850072 2000000, size=1643475 3000000, size=2583958 4000000, size=3398540 5000000, size=4223199 6000000, size=5030981 7000000, size=5838754 8000000, size=6836608 9000000, size=7576135 after loop: 8569358 System.gc(): 569 after clearResources(): 569{noformat} Added patch for *PDFBox 3* [^PDFBox5731_clear_out_unused_COSName_instances_automatically_PDFBOX3.patch] was (Author: axh): [~lycheng] I have created a patch for PDFBox 3. I use a cleanup thread instead, to prevent the memory leak I mentioned earlier. Also the locking should not be on the queue but on nameMap to prevent a race condition that could lead to another memory leak. I am referring to this piece from your proposed code: {code:java} public static void removeNameMapKey() { Reference<? extends COSName> ref; while ((ref = queue.poll()) != null) { synchronized (queue) { Entry entry = (Entry) ref; nameMap.remove(entry.getName()); } } } {code} The output I get from the test code looks good: {noformat} 0, size=570 1000000, size=850072 2000000, size=1643475 3000000, size=2583958 4000000, size=3398540 5000000, size=4223199 6000000, size=5030981 7000000, size=5838754 8000000, size=6836608 9000000, size=7576135 after loop: 8569358 System.gc(): 569 after clearResources(): 569{noformat} Added patch for *PDFBox 3* "PDFBox5731_clear_out_unused_COSName_instances_automatically_PDFBOX3.patch". > 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: COSName.java, > PDFBOX-5731_clear_out_unused_COSName_instances_automatically_PDFBOX2.patch, > PDFBox5731_clear_out_unused_COSName_instances_automatically_PDFBOX3.patch, > 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, > > attempted_fix_for_PDFBOX-5731__clear_out_unused_COSName_instances_automatically_using_cleaner.patch, > image-2023-12-08-16-02-12-293.png, image-2023-12-13-17-04-22-073.png, > image-2023-12-14-18-10-14-278.png, screenshot-1.png, screenshot-2.png, > screenshot-3.png, screenshot-4.png, screenshot-5.png, screenshot-6.png, > screenshot-8.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