# Memory Leak

> Memory a program still holds but does not need now.

**Field:** Software Development  
**Category:** Compilers & Runtimes  
**Also known as:** Memory Leaks, Leaking Memory

## Think of it like

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

## 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

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.

## 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.

## Why it matters

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

## 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.

## Three principles

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

## Related terms

- [Garbage Collection](https://learn.benibix.com/term/development/garbage-collection)
- [Memory Management](https://learn.benibix.com/term/development/memory-management)
- [Heap Memory](https://learn.benibix.com/term/development/heap-memory)
- [Bug](https://learn.benibix.com/term/development/bug)

---

Source: https://learn.benibix.com/term/development/memory-leak
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
