2009-12-11 79 views

回答

7

我還沒有嘗試過,所以我不能保證這將工作,但嘗試Runtime.totalMemory()

+0

這工作,看起來像它顯示的字節大小。 – 2009-12-11 02:47:31

5

你可以得到應用程序運行時信息

Runtime rt = Runtime.getRuntime(); 

    rt.freeMemory(); 
    rt.totalMemory(); 
0

據我所知, 的java.lang.Runtime.freeMemory()方法返回的可用內存在Java虛擬機的數量。調用gc方法可能會增加freeMemory返回的值。

 Also,reading about runtime information about Java is useful sometime when your application is struggling in getting resources. 

你可以試試下面的代碼:`

class HeapTest 
{ 
    public static void main(String[] args) 
    { 
     System.out.println("Hello from Heap\n"); 
     Runtime rt = Runtime.getRuntime(); 
     System.out.println(rt.totalMemory()); 
     System.out.println(rt.freeMemory()); 
    } 

} `