This article will have a simple introduction on new tool – Eclipse Memory Analyzer (previously called SAP memory analyzer) and how to use this tool to find some interesting memory issues. 1. Install Memory Analyzer into Your Eclipse
2. Getting a Heap Dump from Sun Virtual MachinesThe Memory Analyzer can work with HPROF binary formatted heap dumps. Those heap dumps are written by Sun HotSpot and any VM derived from HotSpot. Depending on your scenario, your OS platform and your JDK version, you have different options to acquire a heap dump. Generally, the heap dump file will be generated as java_pid3524.hprof 3. Simplest Way To Find Memory Leaks
So, “java.lang.Object2261945 @ 0×23d04040” costs around 9M shallow heap (which means directly referred memory), and 273 M retained heap (which means all memory directly or un-directly referred). Now, we can know this is the root cause of memory leak. So, what’s next? Of course, next step is trying to find which codes cause this issue? Any information we can use it as start point? You can find the following information –
From this view, the memory is used by java.lang.Thread @ 0×18ff9320 http-8080-1. So, it should be happened within one HTTP request. Then, find this thread within Thread Details section. And click Thread Properties link. Please see And now you may find some hints, such as VendorSearchMediator, SearchVendorByIDsInput etc. Based on these information, you probably find the root codes –
public
SearchVendorByIDsOutput searchVendorByIDs(SearchVendorByIDsInput input) {
List < vendor > vendors = new ArrayList </ vendor >< vendor > (); for (;;) { VendorImpl v = new VendorImpl(); v.setName( " name " ); vendors.add(v); } } </ vendor > 4. How to find the memory occupied unused collections – Powerful Object Query Language 1During the development, you may never notice that a huge number of collections which have been instantiated, but have never been used. An empty ArrayList, created with the default capacity of 10, costs 80 bytes on a 32 bit system, and 144 bytes on a 64 bit system. If the class MyValueStorage is commonly used in our application, and there are 500.000 instances of it in the heap, then there will be 80Mb on a 32 bit system (on 64 bit – 144MB) reserved for the specialValues and erroneousValues lists. But only about 5% from them are ever needed. Therefore, it may be a good idea to use a lazy initialization for these two fields (keep them null untill they are actually used). The cost we have to pay is several “if” statements to avoid running into NullPointerExceptions.
5. How Many Memory used by VendorImpl – Powerful Object Query Language 2
In summary, Eclipse Memory Analyzer is a very powerful memory analyzer tool. And it can easier find potential memory leaks. And you can also find the memory used by any java object. BTW, there are some related blogs which are very useful.http://wiki. eclipse.org/index.php/MemoryAnalyzer - the main entry for this tool http://kohlerm.blogspot.com/ the blog of Markus Kohler, one of the architect of Eclipse Memory Analyzer https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/u/1203, the blog of Krum Tsvetkov |
How to use Eclipse Memory Analyzer to analyze JVM Memeory Issue
2009-12-03 15:10