Skip to content

Memory Leak

Medium — good to knowGeneral Dev

ELI5 — The Vibe Check

A memory leak is when your program keeps grabbing more memory but never gives it back, like filling a bathtub without a drain. Eventually you run out of water (RAM) and everything slows down or crashes. It is sneaky because things work fine at first, then gradually get worse.

Real Talk

A memory leak occurs when a program allocates memory that is never released back to the OS or runtime. In managed languages (JavaScript, Python), leaks happen through unintended references that prevent garbage collection — such as event listeners that are never removed or closures holding large objects. In C/C++, leaks occur from forgetting to call free(). Long-running processes are most affected.

Show Me The Code

// Classic JS memory leak: event listener never removed
function setup() {
  const bigData = new Array(1000000).fill("data");
  document.addEventListener("click", () => {
    console.log(bigData[0]); // bigData can NEVER be GC'd
  });
}
// Fix: store the listener and removeEventListener when done

When You'll Hear This

"The server runs fine for an hour then crashes — probably a memory leak." / "Profile it with Chrome DevTools to find the memory leak."

Made with passive-aggressive love by manoga.digital. Powered by Claude.