The Secret Life of JavaScript: The Garbage Collector
dev.to·1d·
Discuss: DEV
🔗Weak References
Preview
Report Post

How memory leaks happen and how the Mark-and-Sweep algorithm works.


Timothy was staring at the dashboard he was building. It was getting slow. Sluggish.

"I don’t understand," he said. "I am just creating objects. I’m not running heavy calculations. Why is the browser freezing?"

Margaret walked to the chalkboard and drew a large rectangle.

"Because you are running out of space, Timothy. This is the Heap."

The Heap (Memory is Finite)

"The Heap is where JavaScript stores objects, arrays, and functions," Margaret explained. "It is large, but it is not infinite. If you keep allocating memory without freeing it, you exhaust the available space. The browser freezes."

"But I don’t free anything," Timothy said. "I just move to the next function."…

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