I'm creating dynamic CXF clients in my application.
This is the code snippet of client creation:
JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
Client client = factory.createClient("wsdl/hello.wsdl");
Now, when I setup test application with this paramters
java -Djava.io.tmpdir=/tmp/cxf -XX:MetaspaceSize=12m -XX:MaxMetaspaceSize=24m -XX:MaxMetaspaceFreeRatio=80 -XX:MinMetaspaceFreeRatio=40 -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=sums=200 -XX:+ParallelRefProcEnabled -XX:+AggressiveOpts -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/hdump.hprof -XshowSettings -jar classloader-leak.jar
and execute client creation in loop, I'm getting java.lang.OutOfMemoryError: Metaspace exception. I don't know why aren't classes unloaded/ metaspace cleaned up. If somebody can help me here is my testing project. Just build (mvn clean package) it and execute with command line as I did.
I'm using JDK8u77.
I think I found the issue in CXF. Problem is that URLClassLoader which is created inside JaxWsDynamicClientFactory.createClient() is never destroyed.