| 1 |
package driver; |
| 2 |
|
| 3 |
import java.util.ArrayList; |
| 4 |
|
| 5 |
import fileIO.ReadWrite; |
| 6 |
|
| 7 |
public class ClearRam { |
| 8 |
|
| 9 |
public static void main(String[] args){ |
| 10 |
|
| 11 |
for(int i=0; i<2; i++){ |
| 12 |
|
| 13 |
try { |
| 14 |
System.gc(); |
| 15 |
attempt(); |
| 16 |
} catch(final java.lang.OutOfMemoryError e) { |
| 17 |
|
| 18 |
System.err.println("Out of memory at "+((current*8)/(1<<20))+" MB"); |
| 19 |
} |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
public static void attempt(){ |
| 24 |
ArrayList<long[]> list=new ArrayList<long[]>(8000); |
| 25 |
current=0; |
| 26 |
|
| 27 |
while(true){ |
| 28 |
long[] array=null; |
| 29 |
|
| 30 |
array=new long[1<<20]; |
| 31 |
list.add(array); |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
current+=array.length; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
public static void writeJunk(int megs){ |
| 42 |
try { |
| 43 |
long[] old=(long[]) ReadWrite.readObject("JUNK"+megs+".long", false); |
| 44 |
for(int i=1; i<old.length; i++){ |
| 45 |
assert(old[i]==old[i-1]+1); |
| 46 |
} |
| 47 |
} catch (Exception e) { |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
long[] array=new long[megs*(1<<17)]; |
| 54 |
long current=System.nanoTime(); |
| 55 |
for(int i=0; i<array.length; i++){ |
| 56 |
array[i]=current+i; |
| 57 |
} |
| 58 |
ReadWrite.write(array, "JUNK"+megs+".long", false); |
| 59 |
System.err.println("Wrote "+((8*array.length)/(1024000))+" MB junk"); |
| 60 |
} |
| 61 |
|
| 62 |
private static long current=0; |
| 63 |
|
| 64 |
} |