How Garbage Collection Works in Node.js Using the V8 Engine
dev.to·16h·
Discuss: DEV
🗑️Garbage Collection
Preview
Report Post

Overview

Garbage collection in Node.js is primarily managed by the V8 JavaScript engine, which uses several algorithms to automatically reclaim memory that is no longer in use by the application. This process helps avoid memory leaks and keeps your application running smoothly.

Key Concepts

  • Managed Heap: All objects and data are stored in the V8 heap, which is divided into different spaces based on the age and size of objects.
  • Roots & References: Garbage collection starts from a set of root objects (like global variables) and traverses all references. Objects not accessible from these roots are considered garbage.

The Mark-and-Sweep Algorithm

  • Mark Phase: Starting from roots, mark all reachable (still in use) objects.
  • Sweep Phase: Unmarked ob…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help