[ https://issues.apache.org/jira/browse/GROOVY-10957?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17695868#comment-17695868 ]
Nicolas Filotto edited comment on GROOVY-10957 at 3/2/23 7:09 PM: ------------------------------------------------------------------ According to what I could see from different Profilers' reports (JProfiler, MAT, and VisualVM), only the primitive classes have a JNI Global Reference as GC Root. I also called {{InvokerHelper.removeClass(Class)}} on all the classes loaded by my {{CustomClassLoader}} like what is done in {{GroovyClassLoader#clearCache()}} but I get the same result. However, I've just checked and realized that the Integer wrapper class has also a non-empty {{classValueMap}} so I can try to call {{InvokerHelper.removeClass(Class)}} on the wrapper classes too to see if it helps. was (Author: JIRAUSER285918): According to what I could see from different Profilers' reports (JProfiler, MAT, and VisualVM), only the primitive classes have a JNI Global Reference as GC Root. I also called {{InvokerHelper.removeClass(Class)}} only all the classes loaded by my {{CustomClassLoader}} like what is done in {{GroovyClassLoader#clearCache()}} but I get the same result. However, I've just checked and realized that the Integer wrapper class has also a non-empty {{classValueMap}} so I can try to call {{InvokerHelper.removeClass(Class)}} on the wrapper classes too to see if it helps. > 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)