import java.util.*; public class Example { // private static int LOOP_COUNT = Integer.MAX_VALUE; private static int LOOP_COUNT = 100; private static int DEFAULT_LIST_SIZE = 300; // default value (300 = 300MB) public static void main(String... args) { Example example = new Example(); int listSize = DEFAULT_LIST_SIZE; if (args.length > 0) { listSize = Integer.parseInt(args[0]); } for (int i = 0; i < LOOP_COUNT; i++) { example.test(listSize); try { // Thread.sleep(100L); Thread.sleep(500L); // Thread.sleep(1000L); } catch (Exception ignore) {} } } // specify enough size to listSize (depending on your heap setting), // so the ArrayList can be promoted to old gen and can trigger full GC. private void test(int listSize) { List list = new ArrayList(); for (int i = 0; i < listSize; i++) { list.add(new byte[1024 * 1024]); // add 1MB byte array to ArrayList } // clear ArrayList at the end, so it can be GCed at full GC cycle list = new ArrayList(); } }