CMD Simulator

Memory Leaks - Forgetting to free()

Understand memory leaks: allocated memory that is never freed.

Memory Leaks

A memory leak occurs when you allocate memory with malloc but never call free.

Impact

  • Wasted memory; long-running programs can run out of memory
  • Slower over time as the heap fragments
  • In servers, leaks can cause outages

How to Avoid

  • Every malloc should have a matching free
  • Use MemC to see which blocks remain allocated at program end