DEV Community

Cover image for Javascript Memory Management
ikbal arslan
ikbal arslan

Posted on

1

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).

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (1)

Collapse
 
martinfjant profile image
Martin Falk Johansson

What is the purpose of this? Is it unfinished?

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay