6

My Empty infinity loop

    public static void main(String[] args) {
        while (true) {}
    }

And profiling in Java VisualVM (picture) Visual GC

As you can see, I do not create objects. Why change a heap?

Please explain the effect. Why?

couatl
  • 416
  • 4
  • 14

1 Answers1

7

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.

gpeche
  • 21,974
  • 5
  • 38
  • 51
  • How to profile the program, not to produce objects connect VisualVM? – couatl Dec 13 '12 at 21:42
  • I do not think you can. The most you can do is use some OS level tools (vmstat, top, etc). And anyway even if you do not monitor the application with VisualVM, there is JMX, the finalizer thread, the AWT thread etc etc etc. Assume that your application *will have* some thread allocating some resources in the background – gpeche Dec 13 '12 at 21:46