JVM runs out of heap memory allocated for object instantiation.
The Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.
Loading extremely large datasets entirely into memory, memory leaks (e.g. keeping unneeded references in static collections), or setting `-Xmx` heap limit too low.
1import java.util.*;2 3public class Main {4 private static final List<byte[]> LEAK = new ArrayList<>();5 6 public static void main(String[] args) {7 while (true) {8 LEAK.add(new byte[10 * 1024 * 1024]); // Continuously allocates 10MB chunks9 }10 }11}1import java.util.*;2 3public class Main {4 public static void main(String[] args) {5 // Fix 1: Process streams or batches instead of keeping everything in memory6 // Fix 2: Clear collections when processing completes7 List<byte[]> temp = new ArrayList<>();8 temp.add(new byte[1024]);9 // Process data...10 temp.clear(); // Allow GC cleanup11 }12}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
Objects added to `LEAK` remain strongly referenced forever. The GC cannot clean them up, exhausting the JVM heap space.