java-memory-consumer/Main.java

20 lines
636 B
Java
Raw Permalink Normal View History

2025-08-29 14:18:48 +00:00
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
List<ByteBuffer> 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();
}
}
}