Skip to content

Commit be4e7ce

Browse files
committed
Add README for memoryref application
1 parent 0323209 commit be4e7ce

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

memoryref/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Sample to a show memory references in a Java Application
2+
========================================================
3+
4+
This sample application creates objects from classes `A`, `B`, `C`, `D`, `E`, `F`, and `G`.
5+
Each of the previously mentioned classes extend to `Base` class, which creates a significantly
6+
large byte array in the constructor.
7+
8+
Following is the class diagram.
9+
10+
![Class Diagram](classes.png "Class Diagram")
11+
12+
The application is created to demonstrate the references among objects.
13+
14+
The sample application creates an object from class `A` in the main thread and another object from
15+
class `G` in a daemon thread.
16+
17+
The instance created from class `A` references the instances created from other classes as shown below.
18+
19+
![References](references.png "References")
20+
21+
Following is the object diagram showing the object references after the application is started.
22+
23+
![Object Diagram](objects.png "Object Diagram")
24+
25+
### How to run
26+
27+
Use the following command to run the application. The application creates an object from class `A` in
28+
the main thread and another object from class `G` in a daemon thread. After that the application will
29+
wait for a keyboard input.
30+
31+
```bash
32+
java -Xmn1g -Xmx2g -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -javaagent:target/memoryref.jar -jar target/memoryref.jar
33+
```
34+
35+
### Looking at object references using a Heap Dump.
36+
37+
A heap dump can be obtained from following command to look at the object references in heap memory.
38+
39+
```bash
40+
jmap -dump:file=target/heap.hprof $(pgrep -f memoryref)
41+
```
42+
43+
Use [Eclipse Memory Analyzer Tool (MAT)][mat] to analyze the heap dump.
44+
45+
For more information, read following story based on this sample application.
46+
47+
[Basic concepts of Java heap dump analysis with Eclipse Memory Analyzer Tool (MAT)][medium]
48+
49+
[mat]:(https://www.eclipse.org/mat/)
50+
[medium]:(https://medium.com/@chrishantha/basic-concepts-of-java-heap-dump-analysis-with-mat-e3615fd79eb)
51+
52+
Note: Images were created using [draw.io](https://www.draw.io/).

memoryref/classes.png

24.5 KB
Loading

memoryref/objects.png

9.18 KB
Loading

memoryref/references.png

18.1 KB
Loading

0 commit comments

Comments
 (0)