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/README.md at main · chrishantha/sample-java-programs

Expand file tree

/

README.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
49 lines (30 loc) · 1.91 KB
/

README.md

Copy path

File metadata and controls

49 lines (30 loc) · 1.91 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

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.