2 hours ago · 16 min read3264 words · Tech · hide · 0 comments

“JavaScript is garbage collected, so I don’t have to think about memory” is one of the more expensive lies engineers tell themselves. I’ve been writing JavaScript since I was a teenager, and the apps that fall over aren’t falling over because the garbage collector is broken. They’re falling over because someone, often me, on a bad day, kept a reference alive that should have died. This is the deep-dive I’ve wanted to write for years: how V8’s garbage collector actually works, why “leaks” happen anyway, and how to find and fix them, in the browser and in Node.js, because the two environments leak in genuinely different ways for one structural reason that’s easy to miss. The Garbage Collector’s Actual Job What is a memory leak in JavaScript? It’s memory that’s no longer needed but never gets freed, because something in your code still holds a reference to it, even unintentionally. JavaScript doesn’t have leaks the way C does (forgetting to call free()); it has unintended reachability,…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.