/* * TestMemory.java * * Created on 30 November 2001, 14:03 */ package uk.ac.leeds.ccg.andyt.tests; /** * * @author andyt * @version */ public class TestMemory { /** * @param args the command line arguments */ public static void main (String args[]) { // Get runtime instance Runtime runtime=java.lang.Runtime.getRuntime(); // Print out total virtual machine memory System.out.println("runtime.totalMemory() "+runtime.totalMemory()); System.out.println("runtime.totalMemory() is the total amount of memory available:\n" +"This may vary over time, depending on the host environment!"); System.out.println("runtime.freeMemory() "+runtime.freeMemory()); System.out.println("runtime.freeMemory() is an approximation of the amount of free memory available:\n" +"The difference between the top of the heap and the runtime.totalMemory()\n" +"(the heap is memory made available for allocating temporary variables.)"); // Garbage collect and print out total virtual machine memory again System.gc(); System.out.println("runtime.freeMemory() after garbage collecting "+runtime.freeMemory()); // Set some longs for storing amount of available memory long memory1=0; long memory2=0; long time1=0; long time2=0; int arraySize=0; //arraySize=10000000; OutOfMemoryError arraySize=1000000; // Estimate how much memory time for a double[arraySize] System.gc(); System.out.println("runtime.freeMemory() "+runtime.freeMemory()); memory1=runtime.freeMemory(); time1=System.currentTimeMillis(); double[] da1=new double[arraySize]; for (int i=0;i