Skip to content

Commit

Permalink
JVM Memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanglong9344 committed Jan 11, 2018
1 parent a6b0406 commit fdb81c4
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/java_core_basic/JVMMemory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package java_core_basic;

/**
* The memory of JVM
*
* @author ÌÆÁú
*
*/
public class JVMMemory {
public static void main(String[] args) {
final int M = 1024*1024;
long maxMemory = Runtime.getRuntime().maxMemory()/M;
long totalUsedMemory = Runtime.getRuntime().totalMemory()/M;
System.out.println("MaxMemory : " + maxMemory + "M");
System.out.println("TotalUsedMemory: " + totalUsedMemory + "M");

String s = "";
for(int i=0;i<10000;i++){
s += i;
}
System.out.println(s);
totalUsedMemory = Runtime.getRuntime().totalMemory()/M;
System.out.println("TotalUsedMemory: " + totalUsedMemory + "M");

for(int i=0;i<10000_0000;i++){
new String("" + i);
}
totalUsedMemory = Runtime.getRuntime().totalMemory()/M;
System.out.println("TotalUsedMemory: " + totalUsedMemory + "M");
}
}

0 comments on commit fdb81c4

Please sign in to comment.