Questions regarding (VisualVM) profiling

Hello,

today I tested the VisualVM Profiler on my current project and was quite suprised by the data it gave me. To understand the results I got I have some questions:

  • Watching the heap memory usage (monitor tab) I observed that my programm’s used heap memory steadily increases until it hits ~25 MB used the drops to 3-5 MB within seconds and increases again. Is this normal behavior and why does it happen?
  • Watching the thread dispatching I noticed something strange: My gameloop is looping permanently with 1 MS sleep delay build in. I’ve got no other threads and my console output / fps-data suggests that the loop does what it is supposed to do. But the profiler says my loop-thread sleeps ~75% of the time. I think thats quite contradicting. Can someone explain this?
  • The profiler says that a thread called “RMI TCP Connection” allocates A LOT (75%) of data. Also the largest amount of data is char[] … why?

Thanks in advance!

The behavior you’re seeing is normal garbage collection. It’s only a concern if the graph steadily rises – that is, if the low point of the graph keeps rising. The RMI connection is probably the profiler itself.

If your thread is fast enough to run the rest of its logic under 1ms, then a 1ms sleep is indeed going to account for more than half the time. Profiling isn’t very useful for measuring a single method, more for finding the hot spots in a larger program.