What is Stack and Heap Memory and Method Area in JVM ?

Detailed View:

  • Method Area: Holds class-level information and method definitions.
  • Heap Memory: Allocates memory for objects and their instance variables.
  • Stack Memory: Handles method calls, storing parameters, local variables, and method execution contexts.

Summary:

  • Method Area: Contains class definitions and method bytecode.
  • Heap Memory: Stores objects and their instance variables.
  • Stack Memory: Manages method execution contexts, including parameters and local variable.
  • Method Area:

    • The Method Area stores:
      • Class level information, including method definitions (bytecode) and static variables.
      • Constant pool (literal values and symbolic references).
      • Field data, including instance variables and their types.
    • It does not store actual objects or instances; it stores information related to classes and their structure.
  • Heap Memory:

    • The Heap Memory stores:
      • Objects (instances of classes) and their instance variables.
      • When you use new SomeClass(), it allocates memory on the heap for the object and its instance variables.
      • Each object has its own memory allocation in the heap.
  • Stack Memory:

    • The Stack Memory manages:
      • Method execution, including method calls, local variables, and method parameters.
      • Each thread in Java has its own stack, and method calls are managed using stack frames.
      • When a method is called, a new stack frame is created to handle its parameters, local variables, and return values.
      • The stack frame is removed when the method completes execution.
    

Comments

Popular posts from this blog

Collection Framework of Java

What is DBMS ?

Compiler vs Interpreter vs JIT Compiler