Debugging memory issues
Scenario using JProfiler to debug memory issues on your own machine
- Download the trial version of JProfiler http://www.ej-technologies.com/download/jprofiler/trial
- Watch this video for how to use it http://blog.ej-technologies.com/2009/04/in-screencast-below-i-show-strategy-for.html
- If for example the memory leak is in unit tests, you might insert the following code in the tear down method to cause the JVM to take a break between tests to allow you to manually run GC and see which objects created by the test were not cleaned up
@After public void tearDown() throws Exception { testHelper.tearDown(); helper.tearDown(); System.out.println("force a GC here and see what objects remain that should not"); try { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); System.out.println("Enter the line :- "); String s = br.readLine(); System.out.println("You have Entered :- " + s); } catch (IOException e) { e.printStackTrace(); } }
Scenario OutOfMemory exception due to heap space on the Bamboo build
- kick off a build on bamboo
- ssh to the host, wait till it gets to the point in the build you are interested in (watch the real time logs) and then take a dump of the JVM heap like so
~/>ssh -i elasticbamboo.pk root@ec2-174-129-52-168.compute-1.amazonaws.com [root@ip-10-101-51-19 ~]# jps 1406 ElasticAgentBootstrap 5830 Jps 1798 Launcher 2618 surefirebooter897216346249478641.jar [root@ip-10-101-51-19 ~]# jmap -dump:format=b,file=heapdump.bin -F 2618 Attaching to process ID 2618, please wait... Debugger attached successfully. Client compiler detected. JVM version is 17.0-b16 Dumping heap to heapdump.bin ... Finding object size using Printezis bits and skipping over... Finding object size using Printezis bits and skipping over... Finding object size using Printezis bits and skipping over... Finding object size using Printezis bits and skipping over... Finding object size using Printezis bits and skipping over... Finding object size using Printezis bits and skipping over... Finding object size using Printezis bits and skipping over... Finding object size using Printezis bits and skipping over... Finding object size using Printezis bits and skipping over... Heap dump file created [root@ip-10-101-51-19 ~]#exit ~/>scp -i elasticbamboo.pk root@ec2-50-17-14-228.compute-1.amazonaws.com:~/heapdump.bin .
- Visualize the dump
~/Documents/AWSConfig/Sage/AtlassianCreds>jhat -J-Xmx1024m heapdump.bin Reading from heapdump.bin... Dump file created Tue Dec 20 14:17:03 PST 2011 ... WARNING: Failed to resolve object id 0x73ff4960 for field table (signature L) WARNING: Failed to resolve object id 0x740465c0 for field table (signature L) Chasing references, expect 1800 dots.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... .................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... Eliminating duplicate references........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ Snapshot resolved. Started HTTP server on port 7000 Server is ready.
- In your browser go to http://localhost:7000/showInstanceCounts/
- Click on one of the "instance" links near or at the top
- Use “Reference Chains from Rootset” (Exclude weak refs) to see who’s holding the instance