[ https://issues.apache.org/jira/browse/GROOVY-10957?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17695851#comment-17695851 ]
Jochen Theodorou commented on GROOVY-10957: ------------------------------------------- Is it really only primitives? Not for example Integer.class? > How to prevent ClassLoader leaks when using ClassValue? > ------------------------------------------------------- > > Key: GROOVY-10957 > URL: https://issues.apache.org/jira/browse/GROOVY-10957 > Project: Groovy > Issue Type: Question > Affects Versions: 4.0.6 > Reporter: Nicolas Filotto > Priority: Major > Attachments: JNI-Global-Reference.png > > > For my tests, I'm using > [rest-assured|https://github.com/rest-assured/rest-assured] which is > partially written in Groovy. > In my application, I use a custom {{ClassLoader}} to load rest-assured and > Groovy classes, after each test, the {{ClassLoader}} is closed and ready to > be collected by the GC. > In case, I launch my tests with {{-Dgroovy.use.classvalue=false}}, the > {{ClassLoaders}} are properly removed from the heap but when I use > {{-Dgroovy.use.classvalue=true}}, I end up with an OOME. > I can see thanks to my profiler that each {{ClassLoader}} is actually > retained by a JNI Global Reference to each primitive class ({{void.class}}, > {{float.class}}, {{boolean.class}}, {{int.class}}, {{double.class}}, > {{long.class}}, {{char.class}}, {{byte.class}}). > If I naively call {{InvokerHelper.removeClass(Class)}} on each of these > classes, my {{ClassLoaders}} don't have any GC root anymore but > unfortunately, they are still in the heap. > I created a small project to reproduce > https://github.com/essobedo/testCLLeak, any idea/help is more than welcome. > *_Environment:_* > +Java version:+ > {noformat} > openjdk version "11.0.18" 2023-01-17 > OpenJDK Runtime Environment Temurin-11.0.18+10 (build 11.0.18+10) > OpenJDK 64-Bit Server VM Temurin-11.0.18+10 (build 11.0.18+10, mixed mode) > {noformat} > +OS:+ > {noformat} > Darwin LT-C02CP37VMD6R 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 > 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64 x86_64 > {noformat} -- This message was sent by Atlassian Jira (v8.20.10#820010)