My Empty infinity loop
public static void main(String[] args) {
while (true) {}
}
And profiling in Java VisualVM (picture)
As you can see, I do not create objects. Why change a heap?
Please explain the effect. Why?
As long as an object is being referenced, the JVM considers it alive. Once an object is no longer referenced and therefore is not reachable by the application code, the garbage collector removes it and reclaims the unused memory.
Full GC is an important phase in the garbage collection process. During this full GC phase, garbage is collected from all the regions in the JVM heap (Young, Old, Perm, Metaspace). During this phase, the JVM is paused.
Java objects reside in an area called the heap. The heap is created when the JVM starts up and may increase or decrease in size while the application runs. When the heap becomes full, garbage is collected. During the garbage collection objects that are no longer used are cleared, thus making space for new objects.
Basically any Java application is multithreaded, the fact that your main thread does not allocate memory does not mean that the others do not allocate either. In fact it is very likely that by attaching via VisualVM and showing the GC tab you have spawned some threads in the VM to monitor GC resources and feed VisualVM the metrics that become those shiny charts. And that monitoring will likely allocate some resources of its own to do its job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With