Where is the constructor call stored? Stack or heap?

When an object is created and the constructor is called, where is the constructor call stored? is it on the stack or heap?

+4
source share
3 answers

The heap is intended only for storage of objects. Cannot create constructor called on the heap.

This call is made on the stack.

The method call uses the stack. It is used to create stacks of methods. Although the constructor is not a method. But you can always write any logic or task, as is always done in any way. Thus, it is implemented on the stack, like any other method.

+1
source

Parameters and local variables for calling the constructor are stored on the stack until the constructor returns.

, , 1.


1 -... " ", JIT , .

+4

JVM runtime data area for stack and heap as shown below

1) Heap: storage area for objects (one per JVM instance)

2) Java stack: storage for local variables, results of intermediate operations (one per thread)

+1
source

Source: https://habr.com/ru/post/1656446/


All Articles