add demo for how memory is allocated in java
This commit is contained in:
parent
ac6fe30cc1
commit
05c4ce52dc
21
src/main/java/jvm/gc/PrintMemoryAddress.java
Normal file
21
src/main/java/jvm/gc/PrintMemoryAddress.java
Normal file
@ -0,0 +1,21 @@
|
||||
package jvm.gc;
|
||||
|
||||
public class PrintMemoryAddress {
|
||||
public Object getObj() {
|
||||
Object o = new Object();
|
||||
System.out.println(STR."The addree is \{System.identityHashCode(o)}");
|
||||
return o;
|
||||
}
|
||||
|
||||
public void showObj() {
|
||||
Object o = getObj();
|
||||
Object o2 = new Object();
|
||||
System.out.println(STR."Now the addree is \{System.identityHashCode(o)}");
|
||||
System.out.println(STR."The addree of o2 is \{System.identityHashCode(o2)}");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
PrintMemoryAddress printMemoryAddress = new PrintMemoryAddress();
|
||||
printMemoryAddress.showObj();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user