Memory profiling for Java

  • Posted by pieter
  • Friday, March 12, 2010 @ 15:17

Since Java is a garbage collected language, it is easy to forget that one can still leak memory.

After porting the simplechat example to Java (yes, we are adding support for server push in JWt), we were playing around with it and suspected a memory leak.

To diagnose the problem, we searched for a memory profiler. In C++ we have valgrind, but for Java, so far we didn’t find a memory profiler to our liking.

Several candidate profilers are either hard to install, very slow or too entangled with an IDE like Eclipse/Netbeans.

As our server push implementation requires a servlet 3.0 container, we test the simplechat example using an external Jetty 8 prerelease. After some looking around, we stumbled upon tijmp, a lightweight memory profiler, which can be installed easily via apt-get (on Ubuntu 9.04), supports JDK6 (a requirement for Jetty 8), and turns out to work very fast.

Basically we were able to set things up simply by apt-getting the tijmp package, and passing -agentlib:tijmp as an argument to the Java Virtual Machine. When starting the JVM, a small user interface automatically pops up and allows you to request different types of statistics and force garbage collection.

We are still looking for a no-nonsense CPU profiler though…


Contact us for more information
or a personalised quotation