Skip to content
Sharp

Memory Management · interview question

What will happen to the local variables stored on the stack when a method execution is completed in Java?

Multiple choiceEasychapter-14-curatedpremiummemory-managementstack-vs-heap
Choose one answer
Answer and explanation

Correct answer

B. They are automatically deallocated.

Why

When a method execution is completed, its stack frame, including all local variables, is automatically deallocated. This is why the stack is efficient and incurs no overhead for garbage collection on method completion.

Test yourself on Memory Management

A free test with instant, explained results. No account needed.

Start free test
All Memory Management questions →