Here you can find the source of compactMemory()
public static void compactMemory()
//package com.java2s; public class Main { /**//from w w w.j a v a 2 s . c om * Compacts memory as much as possible by allocating huge memory block * and then forcing garbage collection. */ public static void compactMemory() { try { final byte[][] unused = new byte[128][]; for (int i = unused.length; i-- != 0;) { unused[i] = new byte[2000000000]; } } catch (OutOfMemoryError ignore) { } System.gc(); } }