GC collects class metadata when classes are unloaded.
Garbage collection in the JVM interacts with Metaspace by reclaiming memory used by class metadata when classes are no longer needed and are unloaded. This helps manage memory efficiently and prevents leaks. For example, when an application dynamically unloads modules, the associated class metadata is cleared by GC.
Additional Notes
How does JVM garbage collection interact with Metaspace?