0

I am learning How GC work in java,

I am using java 1.8.0_40 64bit

My OS is windows 10

Under visualVM I have install VisualGC plugin.

But when I ran my program, I am not able to see the Histogram under Visual GC

I have also start jstatd on local too.

My program code as below.

public static void main(String[] args) {
        String fName = new String("Check GC Behaviour");
        System.out.println(fName);
        String lName = new String("Again Check GC Behaviour");
        System.out.println(lName);

    }

Please look at the below screen.

enter image description here

Let me know if anyone knows how to solve this.

Thanks

Community
  • 1
  • 1
Alpesh Jikadra
  • 1,692
  • 3
  • 18
  • 38
  • 1
    What do you expect to see for such a short program? This program ends before even a single garbage collection cycle happened. – Holger Aug 20 '18 at 14:02
  • I am running this program in debug mode and try to observe the GC only. because I am learning how GC behave, I want to understand the theory with practical demo. – Alpesh Jikadra Aug 21 '18 at 04:02
  • A stopped program doesn’t produce garbage, so there’s still no reason for the garbage collector to run. If you are lucky, the JMX connection to VisualVM may produce garbage on its own, but that’s entirely detached from your program. – Holger Aug 21 '18 at 06:22
  • @Holger you mean to say that, if program generate Garbage then only Histogram will be visible for any program ? – Alpesh Jikadra Aug 21 '18 at 07:57
  • As far as I know, the histogram shows the statistics for previous garbage collection cycles, so you need at least one garbage collection cycle for seeing anything meaningful there. Since for JVMs like Oracle’s HotSpot JVM, the garbage collector will only do something when a certain amount of memory has been occupied (to suggest that there is a need to do something), none will happen so far. You can see it in the other boxes in your screenshot, whose titles say “*0 collections*” and also display only a tiny fraction of their memory to be in use. – Holger Aug 21 '18 at 08:05
  • That doesn’t have to be the reason for the “Not supported for this JVM” message though. Perhaps, there’s still another problem. However, even if the view worked, it didn’t show anything meaningful for your tiny program. It would be just empty like most of the other views. – Holger Aug 21 '18 at 08:08

0 Answers0