Java doesn't provide an explicit API to unload an individual class on demand. Instead, a class can only become eligible for unloading indirectly, as a side effect of its defining class loader being garbage collected, which itself requires that nothing references the class loader or any class or instance it loaded.
An application server that redeploys a web application without restarting the JVM relies on discarding the old deployment's class loader; if a background thread or static reference from another part of the system still holds onto a class from the old deployment, that entire class loader, and all its classes, leaks memory across redeployments.
A concise interview answer is
You can't unload a single class directly in Java — it only happens indirectly when the class loader that loaded it becomes unreachable and gets garbage collected. This matters most in app servers that support hot redeployment, where a lingering reference to an old class or instance can pin the whole class loader in memory, a classic classloader leak.
Last updated: 11 November 2026
Previous question: How does class loading affect memory usage?
Next question: How do JVM optimizations affect the performance of Java applications?