Ever had your web app slow down after a while or start feeling like it’s chewing through more and more memory? You might have suspected memory leaks , but where exactly do they come from in a browser? How does the browser even decide what memory to free or keep?

I hit this problem recently debugging a single-page app that got sluggish after a few minutes. Some tabs just ballooned their memory usage, and Chrome’s Task Manager was confirming my suspicion: memory just kept climbing.

Turns out, understanding how browsers do garbage collection under the hood cleared up a lot of mystery. It’s not just about your JavaScript variables. The DOM, event listeners, and even closures can silently hold onto memory long after you think you’re done with them.

Let’s walk through what’s really going on.

Garbage collection basics: the browser’s janitor