Académique Documents
Professionnel Documents
Culture Documents
Elena Nayashkova
SAP AG
© 2008 by SAP AG, Made available under the Eclipse Public License v1.0
Agenda
1. Concepts
2. Automated Memory Leak Report
3. Developer’s Use Case - Finding the Needle…
4. Summary
5. Q&A
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 2
Introduction
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 3
Causes of Memory Leaks in Java
Unregistered Listeners
Huge Sessions
Forgotten Threads
Blocking Finalizers
etc.
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 4
HPROF Binary Heap Dump
A heap dump is a snapshot of objects that are alive at one point in time.
It contains:
Objects: fields, references, primitive values, …
Classes: class loader, super class, static fields, …
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 6
How to Get a Heap Dump
Non-Interactive
-XX:+HeapDumpOnOutOfMemoryError I BM
end VMs:
of th
e ye
a r
On Demand
JDK1.4.2_12 and -XX:+HeapDumpOnCtrlBreak
JDK6 and Jconsole
More…
http://wiki.eclipse.org/index.php/MemoryAnalyzer#Getting_a_Heap_Dump
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 7
Definition of Retained Set and Retained Size
Retained heap of X is the sum of shallow sizes of all objects in the retained set of X,
i.e. memory kept alive by X
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 8
Dominator Tree
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 9
Dominator Tree: Benefits
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 10
Dominator Tree: Benefits
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 11
Agenda
1. Concepts
2. Automated Memory Leak Report
3. Developer’s Use Case - Finding the Needle…
4. Summary
5. Q&A
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 12
Behind the Scenes
1101010
0101010 A heap dump is written to the file system
0111111
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 13
Demo
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 14
Report Overview
Search by keywords:
identify if problem is
known
Accumulated
objects
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 16
© SAP 2008 / Page 16
Agenda
1. Concepts
2. Finding Memory Leaks
3. Developer’s Use Case - Finding the Needle…
4. Summary
5. Q&A
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 17
Demo
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 18
Inefficient Data Structures
Degenerated Hashtable
Duplicate Strings
Unused Collections
Class Node
{
List children =
new ArrayList();
}
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 19
Agenda
1. Concepts
2. Finding Memory Leaks
3. Developer’s Use Case - Finding the Needle…
4. Summary
5. Q&A
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 20
Summary
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 21
Agenda
1. Concepts
2. Finding Memory Leaks
3. Developer’s Use Case - Finding the Needle…
4. Summary
5. Q&A
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 22
Thank you!
Elena Nayashkova
SAP AG
Blogs:
dev.eclipse.org/blogs/memoryanalyzer
Memory Analysis in a Nutshell | © 2008 by SAP AG; Made available under the EPL v1.0 | Page 23