Analyzing Memory Consumption

You analyze the heap dumps to find areas for optimization:

Class Histogram Memory Analyzer provides a developer with a possibility to focus on a particular piece of code. by using filters in the Class Histogram:

Immediate Dominators When you have found a suspect, that consumes a lot of memory, you can use the dominators query to find out what keeps this suspect in memory. With this query you can also skip the dominators that are of no interest for you, e.g. java.* packages:

OQL

The two most common ways to "waste" memory are:


  • Inefficient use of data structures, like keeping millions of empty lists or HashMaps. With OQL you can easily find e.g. all instances of ArrayList which are empty and have never been modified:
    SELECT * FROM java.util.ArrayList WHERE size=0 AND modCount=0
  • A lot of redundant data, e.g. redundant Strings or char[] . Below you can find two examples of OQL queries to operate with Strings:
    SELECT * FROM java.lang.String s WHERE s.count >= 100
    SELECT * FROM java.lang.String s WHERE toString(s) LIKE ".*day"