How to view variable occupies memory size

Category: Java SE
 
xiaopingzileo
2010-02-19 09:26:57

Sponsored Links
I want to see the variable occupies memory size,
ask the following code have any questions, print out the result is 0?

.....
; final int NMAX = 10;

long mem1 = Runtime.getRuntime (). freeMemory ();
System.out.println ("Free Memeory ; 1: "+ mem1);

/ / allocate the ; triangle array
int [] [] odds = new int [NMAX] [];
; for (int i = 0; i <NMAX; i + +)
odds [i] = new int [i +1];

long mem2 = Runtime.getRuntime (). freeMemory ();
; System.out.println ("Free Memeory 2:" + mem2);

; long uMem = mem1 - mem2;
System.out.println ("Used memory:" + uMem);
....

Sponsored Links

Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.