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 — Add README for memoryref application · chrishantha/sample-java-programs@be4e7ce

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • memoryref
    • README.md
    • classes.png
    • objects.png
    • references.png
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎memoryref/README.md‎

Copy file name to clipboard
+52Lines changed: 52 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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/).
Collapse file

‎memoryref/classes.png‎

Copy file name to clipboard
24.5 KB
  • Display the source diff
  • Display the rich diff
Loading
Collapse file

‎memoryref/objects.png‎

Copy file name to clipboard
9.18 KB
  • Display the source diff
  • Display the rich diff
Loading
Collapse file

‎memoryref/references.png‎

Copy file name to clipboard
18.1 KB
  • Display the source diff
  • Display the rich diff
Loading

0 commit comments

Comments
0 (0)
You are visitor 01402792 — 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.