Home / Questions / Example: OutOfMemoryError
Explanatory Question

Example: OutOfMemoryError

👁 33 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation


import java.util.ArrayList;

public class ErrorExample2 {
    public static void main(String[] args) {
        ArrayList<int[]> list = new ArrayList<>();
        while (true) {
            list.add(new int[1000000]); // Keep allocating memory
        }
    }
}