Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Outline

Sample to a show memory references in a Java Application

This sample application creates objects from classes A, B, C, D, E, F, and G. Each of the previously mentioned classes extend to Base class, which creates a significantly large byte array in the constructor.

Following is the class diagram.

Class Diagram

The application is created to demonstrate the references among objects.

The sample application creates an object from class A in the main thread and another object from class G in a daemon thread.

The instance created from class A references the instances created from other classes as shown below.

References

Following is the object diagram showing the object references after the application is started.

Object Diagram

How to run

Use the following command to run the application. The application creates an object from class A in the main thread and another object from class G in a daemon thread. After that the application will wait for a keyboard input.

java -Xmn1g -Xmx2g -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -javaagent:target/memoryref.jar -jar target/memoryref.jar

Looking at object references using a Heap Dump.

A heap dump can be obtained from following command to look at the object references in heap memory.

jmap -dump:file=target/heap.hprof $(pgrep -f memoryref)

Use Eclipse Memory Analyzer Tool (MAT) to analyze the heap dump.

For more information, read following story based on this sample application.

Basic concepts of Java heap dump analysis with Eclipse Memory Analyzer Tool (MAT)

Note: Images were created using draw.io.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.