GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — sample-java-programs/memoryref at master · odissea/sample-java-programs

Expand file tree

/

memoryref

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

memoryref

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
src/main
src/main
 
 
README.md
README.md
 
 
classes.png
classes.png
 
 
objects.png
objects.png
 
 
pom.xml
pom.xml
 
 
references.png
references.png
 
 

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.

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.