Tracking Memory Leaks: Difference between revisions

From Event-B
Jump to navigationJump to search
imported>Mathieu
m Imported from http://rodin-b-sharp.wiki.sourceforge.net/Tracking+Memory+Leaks
 
imported>Mathieu
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
It can happen that a plug-in consumes a lot of memory, and, worse, never
It can happen that a plug-in consumes a lot of memory, and, worse, never releases it. This recently happened to the new Predicate Prover
releases it. This recently happened to the new Predicate Prover
plug-in. While looking for a proof, it was allocating megabytes of memory, and upon cancellation the memory was not garbage collected. This
plug-in. While looking for a proof, it was allocating megabytes of
impeded seriously proving, as attempting to use this prover was allocating memory that was never freed. Users then had to manually
memory, and upon cancellation the memory was not garbage collected. This
restart the platform every third or fourth attempt of using this prover.  
impeded seriously proving, as attempting to use this prover was
allocating memory that was never freed. Users then had to manually
restart the platform every third or fourth attempt of using this prover.


This document explains how such memory leaks can be examined and how one
This document explains how such memory leaks can be examined and how one can trace their origin using simple useful tools. The proposed method
can trace their origin using simple useful tools. The proposed method
consists in using the JVM heap dump feature, together with an external tool for inquiring into a heap dump.
consists in using the JVM heap dump feature, together with an external
tool for inquiring into a heap dump.


==Producing a Heap Dump==
==Producing a Heap Dump==


This document supposes that the standard JVM from Sun (or the one
This document supposes that the standard JVM from Sun (or the one bundled with Mac OS X) is used.
bundled with Mac OS X) is used.


To produce a heap dump, add the following VM argument to the command
To produce a heap dump, add the following VM argument to the command used to launch the platform (e.g., in the {{menu|Arguments}} tab of the {{menu|Run}} dialog of Eclipse):
used to launch the platform (e.g., in the {{menu|Arguments}} tab of the
{{menu|Run}} dialog of Eclipse):
<pre>
<pre>
   -Xrunhprof:format=b,file=/tmp/xx.hprof
   -Xrunhprof:format=b,file=/tmp/xx.hprof
</pre>
</pre>


When given this argument, he JVM will write in the specified file (here
When given this argument, he JVM will write in the specified file (here {{file|/tmp/xx.hprof}}) a copy of the heap upon program termination. It is also possible to force a heap dump while the application is running by sending a QUIT signal (number 3) to the JVM while it is running (I don't know how to do that on Windows platforms).
{{file|/tmp/xx.hprof}}) a copy of the heap upon program termination. It is
also possible to force a heap dump while the application is running by
sending a QUIT signal (number 3) to the JVM while it is running (I don't
know how to do that on Windows platforms).


==Analysing a Heap Dump==
==Analysing a Heap Dump==


With the Java 6 JDK, there is a bundled tool called {{ident|jhat}} that allows
With the Java 6 JDK, there is a bundled tool called {{ident|jhat}} that allows to analyse a heap dump. However, SAP developed another tool based on
to analyse a heap dump. However, SAP developed another tool based on
Eclipse which is more user-friendly and easy to use. This tool is available from (free registration required):
Eclipse which is more user-friendly and easy to use. This tool is
available from (free registration required):


https://www.sdn.sap.com/irj/sdn/wiki?path=/display/Java/Java+Memory+Analysis
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/Java/Java+Memory+Analysis


The online help of the tool is very well done and gives various strategies
The online help of the tool is very well done and gives various strategies for analysing the allocated memory at the time of the dump.
for analysing the allocated memory at the time of the dump.
 
 
[[Category:Developer documentation]]

Latest revision as of 11:03, 10 November 2008

It can happen that a plug-in consumes a lot of memory, and, worse, never releases it. This recently happened to the new Predicate Prover plug-in. While looking for a proof, it was allocating megabytes of memory, and upon cancellation the memory was not garbage collected. This impeded seriously proving, as attempting to use this prover was allocating memory that was never freed. Users then had to manually restart the platform every third or fourth attempt of using this prover.

This document explains how such memory leaks can be examined and how one can trace their origin using simple useful tools. The proposed method consists in using the JVM heap dump feature, together with an external tool for inquiring into a heap dump.

Producing a Heap Dump

This document supposes that the standard JVM from Sun (or the one bundled with Mac OS X) is used.

To produce a heap dump, add the following VM argument to the command used to launch the platform (e.g., in the Arguments tab of the Run dialog of Eclipse):

  -Xrunhprof:format=b,file=/tmp/xx.hprof

When given this argument, he JVM will write in the specified file (here

/tmp/xx.hprof

) a copy of the heap upon program termination. It is also possible to force a heap dump while the application is running by sending a QUIT signal (number 3) to the JVM while it is running (I don't know how to do that on Windows platforms).

Analysing a Heap Dump

With the Java 6 JDK, there is a bundled tool called

jhat

that allows to analyse a heap dump. However, SAP developed another tool based on

Eclipse which is more user-friendly and easy to use. This tool is available from (free registration required):

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/Java/Java+Memory+Analysis

The online help of the tool is very well done and gives various strategies for analysing the allocated memory at the time of the dump.