Junior — Middle
In which part of JVM memory are new objects created during program execution?
sobes.tech AI
Answer from AI
In the JVM, new objects are created in a memory area called the heap. The heap is a dynamic memory area allocated for storing objects during program execution.
When an object is created using the new operator, memory for it is allocated on the heap. Memory management in the heap is handled by the garbage collector, which automatically frees memory occupied by objects that are no longer referenced.
Example:
MyClass obj = new MyClass(); // object is created on the heap
Unlike the stack, where local variables and method calls are stored, the heap is intended for objects with a dynamic lifespan.