What does Runtime.maxMemory() return exactly? I have this program:


public class MaxMemory{


    private static String uft(){
        Runtime rt = Runtime.getRuntime();
        long free = rt.freeMemory(), total = rt.totalMemory(), used =  total - free;
        long max = rt.maxMemory();
        java.text.NumberFormat nf = java.text.NumberFormat.getInstance() ;
        return "used: "+nf.format(used)+" free: "+nf.format(free)+
            " total: "+nf.format(total)+" max: "+nf.format(max);
    }
    public static void main(String[] args){
        System.out.println("before we start: "+uft());
        java.util.HashSet al = new java.util.HashSet(1024);
        int i = 0;
        byte[] barrier = new byte[2048];
        while(true) try{
            al.add(new byte[1024]);
            i++;
        } catch(OutOfMemoryError e){
            barrier = null;
            break;
        }
        System.out.println("after "+i+"k "+uft());

    }
} // MaxMemory

When I run it I get:
[EMAIL PROTECTED] ] java MaxMemory
before we start: used: 318,832 free: 1,712,784 total: 2,031,616 max: 134,217,728
after 61993k used: 66,649,312 free: 800 total: 66,650,112 max: 134,217,728
[EMAIL PROTECTED] ] java -Xmx128m MaxMemory
before we start: used: 318,832 free: 1,712,784 total: 2,031,616 max: 201,326,592
after 123587k used: 133,233,920 free: 768 total: 133,234,688 max: 201,326,592
[EMAIL PROTECTED] ] java -version
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)



----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



Reply via email to