Search This Blog

Wednesday, September 15, 2010

Java heap dump

I recently worked on a project where I was faced with "out of memory" problem. Exception appeared usually after the application has worked for several weeks. I solved the problem with VisualVM tool that ships with Java 1.6 JDK.
VisualVM tool provides a direct connection to any Virtual Machine locally or remote, or can load heap dump or thread dump from a file.

To dump heap memory to a file type in console(linux):
  1. Get java process id
    ps -eaf | grep java
  2. Dump heap memory to a file using jmap ("jmap prints shared object memory maps or heap memory details of a given process or core file or a remote debug server")
    jmap -heap:format=b PID (where PID i id of your java process)
  3. Run jvisualvm
    jvisualvm -J-Xmx512M
  4. Load heap.bin file
  5. Find biggest objects by retained size. After file loads you can see every object that was in memory at the time the dump was taken.Click on find biggest objects by retained size and you will get hierarchy of biggest objects in memory.
In this way, I discovered that I have HashMap object in some other singleton object, and the values were added to map, but never removed.

10 comments:

  1. where heap.bin file located in linux operating system.

    ReplyDelete
    Replies
    1. Option 1. You could find it:
      find / -name "heap.bin" -type f 2>/dev/null

      Option 2.
      It should be located in the working directory of the process, which you can get by:

      1. Get process id:
      ps aux | grep java

      2. Get working directory
      pwdx PID (where PID is what you got from step 1)

      Delete
  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.


    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete
  3. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
    rpa training in bangalore
    best rpa training in bangalore
    RPA training in bangalore
    rpa course in bangalore
    rpa training in chennai
    rpa online training

    ReplyDelete
  4. Some us know all relating to the compelling medium you present powerful steps on this blog and therefore strongly encourage contribution from other ones on this subject while our own child is truly discovering a great deal. Have fun with the remaining portion of the year.
    Python Online certification training
    python Training institute in Chennai
    Python training institute in Bangalore

    ReplyDelete
  5. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

    AWS Training in Bangalore | Best AWS Amazon Web Services…
    Amazon Web Services (AWS) Training in Pune India
    AWS Training | AWS Training and Certification | AWS online training
    AWS Training in Bangalore cost| Aws training in Bangalore with placements

    ReplyDelete
  6. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
    microsoft azure training in bangalore
    rpa training in bangalore
    best rpa training in bangalore
    rpa online training

    ReplyDelete
  7. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. 
    AWS training in chennai

    AWS Training in Bangalore

    ReplyDelete
  8. I would like to thank you for your nicely written post, its informative and your writing style encouraged me to read it till end. Thanks

    Splunk Training | Splunk Training Institute | Splunk Training in Chennai | Splunk Training Institute in Chennai

    Python Training | Python Course | Python Training in Chennai | Python Course in Chennai

    ReplyDelete