JavaVM 最大ヒープサイズの指定

戻る


$ ./HeapTest.sh

DEFAULT:
i=2753536
i=2754560
	利用可能なメモリ容量=343584
	全メモリ容量=66650112
i=2755584
i=2756608
i=2757632
i=2758656
i=2759680
i=2760704
i=2761728
i=2762752
i=2763776
i=2764800
	利用可能なメモリ容量=95120
	全メモリ容量=66650112
i=2765824
i=2766848
i=2767872
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

in case of option -Xmx64m:
i=2753536
i=2754560
	利用可能なメモリ容量=343584
	全メモリ容量=66650112
i=2755584
i=2756608
i=2757632
i=2758656
i=2759680
i=2760704
i=2761728
i=2762752
i=2763776
i=2764800
	利用可能なメモリ容量=95120
	全メモリ容量=66650112
i=2765824
i=2766848
i=2767872
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

in case of option -Xmx128m:
i=5528576
i=5529600
	利用可能なメモリ容量=325472
	全メモリ容量=133234688
i=5530624
i=5531648
i=5532672
i=5533696
i=5534720
i=5535744
i=5536768
i=5537792
i=5538816
i=5539840
	利用可能なメモリ容量=76928
	全メモリ容量=133234688
i=5540864
i=5541888
i=5542912
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space




#!/bin/sh
# $Id: heap.html,v 1.1 2009/06/22 16:12:12 kishi Exp kishi $

echo "DEFAULT:"
java -cp . HeapTest 2>&1 | tail -20

echo ""
echo "in case of option -Xmx64m:"
java -cp . -Xmx64m HeapTest 2>&1 | tail -20

echo ""
echo "in case of option -Xmx128m:"
java -cp . -Xmx128m HeapTest 2>&1 | tail -20


import java.util.*;

/**
$Id: heap.html,v 1.1 2009/06/22 16:12:12 kishi Exp kishi $
@author KISHI Yasuhiro
*/

public class HeapTest {

    private List list;

    public HeapTest() {
        this.list = new LinkedList();
    }

    public void add
        ( Object object ) {
        list.add( object );
    }

    static public void main( String[] args ) {

        HeapTest ht = new HeapTest();
        String[] arr = new String[ 1024 ];
        for ( int i = 0; i < arr.length; i++ ) {
            arr[ i ] = new String( "1234567890" );
        }

        int i = 0;
        int j = 0;
        while ( true ) {
            ht.add( arr );
            if ( ( ++i % 1024 ) == 0 ) {
                System.out.println( "i=" + i );

                if ( ++j % 10 == 0 ) {
                    Runtime rt = Runtime.getRuntime();
                    System.out.println( "\t利用可能なメモリ容量=" + rt.freeMemory() );
                    System.out.println( "\t全メモリ容量=" + rt.totalMemory() );
                }

            }

        }


    }

}



戻る inserted by FC2 system