blob: ca19c1c5b941ce8fb86ac4f589ff21f201f45ccf [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2008, 2012 SAP AG and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
which accompanies this distribution, and is available at
https://www.eclipse.org/legal/epl-2.0/
SPDX-License-Identifier: EPL-2.0
Contributors:
SAP AG - initial API and implementation
-->
<!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "reference.dtd" >
<reference id="ref_analyzingmemoryconsumption" xml:lang="en-us">
<title>Analyzing Memory Consumption</title>
<shortdesc />
<prolog>
<copyright>
<copyryear year=""></copyryear>
<copyrholder>
Copyright (c) 2008, 2010 SAP AG and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
which accompanies this distribution, and is available at
https://www.eclipse.org/legal/epl-2.0/
</copyrholder>
</copyright>
</prolog>
<refbody>
<section>
<p>
An easy way to start looking for areas for optimization is to use the <xref href="inspections/component_report.dita">Component Report</xref>.
Additionally, the following queries may be useful to perform the analysis manually:
</p>
<simpletable relcolwidth="2* 3*"
id="analyzingmemoryconsumptiontable">
<strow>
<stentry>Class Histogram</stentry>
<stentry>
Memory Analyzer provides a developer with a
possibility to focus on a particular piece
of code by using filters in the Class
Histogram:
<image href="../mimes/7507ab60.png" align="left" placement="break">
<alt>Filter of java.util.* in top row of histogram</alt>
</image>
</stentry>
</strow>
<strow>
<stentry>Retained Set</stentry>
<stentry>
Looking what a set of objects retains (how much memory and what types of
objects) may give some ideas where to optimize.
</stentry>
</strow>
<strow>
<stentry>Collections query group</stentry>
<stentry>
A number of queries provided under the <b>Collections</b> query group give the opportunity
to analyze the ways collections are used e.g. how much they are filled, what the sizes are,
what the collision ratio (for hash maps) is, etc... See <xref href="../tasks/analyzingjavacollectionusage.dita">Analyzing Java Collection Usage</xref>.
</stentry>
</strow>
<strow>
<stentry>Group by Value</stentry>
<stentry>
The Group by Value query provides the possibility to group a set of objects
by the value of a certain field. It is very useful for searching redundant
data.
</stentry>
</strow>
<strow>
<stentry>Immediate Dominators</stentry>
<stentry>
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.
<cmdname>java.*</cmdname>
packages:
<image href="../mimes/m317da505.png" align="left" placement="break">
<alt>skip parameter in query wizard for immediate dominators query</alt>
</image>image>
</stentry>
</strow>
<strow>
<stentry>OQL</stentry>
<stentry>
<p>
The two most common ways to "waste" memory
are:
</p>
<ul>
<li>
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:
<codeblock>SELECT * FROM java.util.ArrayList WHERE size=0 AND modCount=0</codeblock>
</li>
<li>
A lot of redundant data, e.g. redundant
<cmdname>Strings</cmdname>
or
<cmdname>char[]</cmdname>
. Below you can find two examples of OQL
queries to operate with Strings:
<codeblock>SELECT * FROM java.lang.String s WHERE s.count &gt;= 100</codeblock>
<codeblock>SELECT * FROM java.lang.String s WHERE toString(s) LIKE ".*day"</codeblock>
</li>
</ul>
</stentry>
</strow>
</simpletable>
</section>
</refbody>
</reference>