DEV Community

Cover image for Javascript Memory Management
ikbal arslan
ikbal arslan

Posted on

Javascript Memory Management

When the javascript engine starts executing the code it will store variables inside of the memory. for storing data, runtime uses two different memory:

  • Stack memory
  • Heap memory

Javascript only can communicate with stack memory.

Before explaining the differences around these memories I should explain the data types in javascript. In javascript, we have two different data types:

  • Primitive types: primitive types stored directly in the stack
    • String, Number, Boolean, Null, Undefined, Symbol, BigInt

  • Reference types: Stored in the heap and accessed by reference from Stack
    • Arrays, Functions, Objects

Image description

For maximum optimization in the memory space javascript engine uses something called garbage collector. it will clean the value immediately when a value is not reachable via a variable(label).

Top comments (1)

martinfjant profile image
Martin Falk Johansson

What is the purpose of this? Is it unfinished?