Supriya Singh’s Post

What causes OutOfMemoryError vs StackOverflowError? Here’s the answer: Both are runtime errors, but they happen in different memory regions. OutOfMemoryError (OOME) Occurs when the JVM cannot allocate memory in the Heap. Common Causes: • Creating too many objects • Memory leaks (objects not released) • Very large collections (e.g., huge ArrayList) • Excessive class loading → Metaspace full Eg: List<int[]> list = new ArrayList<>(); while (true) { list.add(new int[1000000]); // keeps filling heap } Eventually, Heap memory is exhausted. StackOverflowError (SOE) Occurs when the Stack memory of a thread is full. Common Causes: • Infinite or deep recursion • Too many nested method calls Eg: void recurse() { recurse(); // no exit condition } Each method call adds a frame to the stack → stack limit exceeded. OutOfMemoryError happens when Heap memory is exhausted, usually due to too many objects or leaks, while StackOverflowError occurs when the thread’s stack memory is full, typically due to deep or infinite recursion. Follow Supriya Singh for more such interesting and helpful posts. #Java #Programming #InterviewPrep #JavaDeveloper

  • graphical user interface, text, application, chat or text message

This is explained really well 👍, can be revised before interviews quickly, keep posting!

Interview prep improves when concepts are internalized. What Supriya Singh shared helps candidates move beyond memorization and build genuine confidence in Java fundamentals.

See more comments

To view or add a comment, sign in

Explore content categories