I have three modules: module-a, module-b, module-c. Module-a and module-b are in the boot layer. I create a layer for module-c myself. Module-c has a JPMS implementation of the service whose interface is in module-a.
So I create a layer with module-c in module-b.
ModuleFinder finder = ModuleFinder.of(moduleCPath); ModuleLayer parent = ModuleLayer.boot(); Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("module-c")); ClassLoader scl = ClassLoader.getSystemClassLoader(); ModuleLayer layer = parent.defineModulesWithOneLoader(cf, scl);
Then in module-b, I call the service from module-c. After completing the service, I no longer need module-c and the newly created layer. How to remove it from the JVM and free all resources? Is layer = null; enough to do layer = null; ?
source share