Nicolas Filotto created GROOVY-10957:
----------------------------------------

             Summary: 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
            Reporter: Nicolas Filotto
         Attachments: JNI-Global-Reference.png

I'm using [rest-assured|https://github.com/rest-assured/rest-assured] for my 
tests 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 released 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 {{ClassLoader}}s don't have any GC root anymore but unfortunatlly 
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.



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

Reply via email to