Steps in the memory allocation process for Java objects

后端 未结 3 594
感动是毒
感动是毒 2020-12-01 21:10

What happens in the memory when a class instantiates the following object?

public class SomeObject{

    private String strSomeProperty;

          


        
3条回答
  •  旧时难觅i
    2020-12-01 21:59

    Points to remember:

    1. When a method is called, a frame is created on the top of stack.
    2. Once a method has completed execution, flow of control returns to the calling method and its corresponding stack frame is flushed.
    3. Local variables are created in the stack.
    4. Instance variables are created in the heap & are part of the object they belong to.
    5. Reference variables are created in the stack.

    Ref: http://www.javatutorialhub.com/java-stack-heap.html

提交回复
热议问题