import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; //TIP To Run code, press or // click the icon in the gutter. public class Main { public static void main(String[] args) { List buffers = new ArrayList<>(); try { while (true) { buffers.add(ByteBuffer.allocateDirect(10 * 1024 * 1024)); // 10MB each } } catch (OutOfMemoryError e) { System.err.println("OutOfMemoryError: " + e.getMessage()); e.printStackTrace(); } } }