JPMS module layers enable dynamic plug-in architectures in Java, but removing layers requires careful handling to ensure class unloading occurs and memory leaks are avoided. Without explicit GC triggers, the G1 collector only unloads classes during full GC cycles. Using G1PeriodicGCInterval (JDK 12+) or low-pause collectors like Shenandoah/ZGC can prompt timely class unloading. When classes fail to unload, class loader leaks occur and can eventually cause OutOfMemoryErrors. Diagnosing these leaks involves JDK Flight Recorder for detecting missing unload events, and Eclipse MAT heap dump analysis to trace GC root paths and find lingering references. The Layrry framework is used as a practical example throughout.
Sort: