When all classes loaded by the class loader no longer have links, and all links to the class loader have been deleted, the class loader and loaded classes will collect garbage as a group.
Note that this depends on whether the JVM attribute is set, which unloads unwritten classes. It is installed by default in most environments, but may not be in some built-in cases.
[Note that this is not a trivial question to remove class references. Any other class that refers to it by name will, of course, prevent deletion. Therefore, the class must be loaded using ClassLoader.findClass or something similar.]
Hot licks
source share