I can offer some (documented) clarifications here.
The metaspace is NOT in the heap. What you may be recalling, Brad, was that there was some question in Java 7 and earlier about whether the PERM space was in the heap or not. But the metaspace (new in Java 8 and above) is definitely NOT. Instead, it’s taken from available memory on the box (native or OS memory).
For any who may prefer to hear that from Oracle rather than me :), it’s documented in various places, such as here:
“Starting with JDK 8, the permanent generation was removed and the class metadata is allocated in native memory. The amount of native memory that can be used for class metadata is by default unlimited. Use the option -XX:MaxMetaspaceSize to put an upper limit on the amount of native memory used for class metadata.”
But indeed as you say, GCs can help impact the metaspace used, at least if objects are GCed (from the heap) whose classes are then unloaded, as the document says later:
“Class metadata is deallocated when the corresponding Java class is unloaded. Java classes are unloaded as a result of garbage collection, and garbage collections may be induced to unload classes and deallocate class metadata.”
Finally yes, as you say (and I did earlier), it is possible to observe the metaspace as well as other Java memory spaces (heap and non-heap) in FR, as well as in other tools.