Skip to content
BENIBIX Learn

Memory Leak

Also known as Memory Leaks, Leaking Memory

Memory a program still holds but does not need now.

Think of it like

Think of it like a tap left dripping into a sink. Slowly the sink fills and spills over.

Example

Jack's server adds every request to a global list for debugging and never clears it. It uses 200 MB on Monday and 4 GB by Friday, then crashes.

Why it matters

Leaks hide in testing, because tests are short. They show up days later in production as slow pages and crashes.

Definition

A memory leak is memory a program keeps holding after it no longer needs it. Each leak may be small, but it happens again and again. The program uses more and more memory the longer it runs. In the end it slows down or crashes. Leaks happen in every language, including those with garbage collection, when code keeps links to old data.

Example code

javascript
const seen = [];
app.get('/', (req, res) => {
  seen.push(req);   // never removed: the list grows forever
  res.send('ok');
});
Each visit adds one more request to a list. Nothing ever empties it.

Common mistake

Restarting the server each night to hide the leak. The fix is to find what keeps growing. Often it is a list, a cache or an event listener.

Key takeaways

  1. 1
    Kept, not needed. Memory never returned.
  2. 2
    Grows over time. Slow, then a crash.
  3. 3
    Any language. Even with garbage collection.