import groovy.lang.GroovyClassLoader; class LeakDynamic { public static interface TestClass { String getThingy(); } static String getTheThingy() { return "the thingy"; } @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { for (int i = 0; i < 1000; i++) { var cl = new GroovyClassLoader(); var c = cl.parseClass("class TestClass" + i + " implements LeakDynamic.TestClass { public String getThingy() { return LeakDynamic.getTheThingy(); } }"); var t = (TestClass) c.getConstructor().newInstance(); assert t.getThingy() == getTheThingy(); } } }