1 import java
.util
.Vector
;
4 * Under JavaSoft's VM they arbitarily limit the amount of memory
5 * a Java application can use (though this can be overridden). The
6 * point here is to check to see whether or not an application being
7 * run by Japhar will ever get the OutOfMemoryError or not when resources
10 public class OutOfMemoryErrorTest
12 public static void main(String
[] argv
)
16 long free
= 0, total
= 0;
17 // quickly approach memory limit 1M at a time
19 r
= Runtime
.getRuntime();
23 v
.addElement(new byte[1048576]);
26 // out of memory error
27 catch (OutOfMemoryError oomerr1
)
29 // slowly encroach on memory limit 2 bytes+ at a time
33 v
.addElement(new byte[2]);
36 // out of memory error
37 catch (OutOfMemoryError oomerr2
)
41 free
= r
.freeMemory();
42 total
= r
.totalMemory();
45 // System.out.println("free = " + free);
46 // System.out.println("total = " + total);
47 System
.out
.println("PASSED: ");
50 System
.out
.println("FAILED: runtime unknown");
56 System
.out
.println("FAILED: unexpected error");
61 System
.out
.println("FAILED: unexpected exception");