What happens when memory is allocated (typically with malloc) but not freed (with free()).

This gives rise to unusable memory which goes away when the process ends on real Operating Systems, or is lost forever on toy Operating Systems such as Windows 3.x.

memory farts = M = memory smash

memory leak n.

An error in a program's dynamic-store allocation logic that causes it to fail to reclaim discarded memory, leading to eventual collapse due to memory exhaustion. Also (esp. at CMU) called core leak. These problems were severe on older machines with small, fixed-size address spaces, and special "leak detection" tools were commonly written to root them out. With the advent of virtual memory, it is unfortunately easier to be sloppy about wasting a bit of memory (although when you run out of memory on a VM machine, it means you've got a real leak!). See aliasing bug, fandango on core, smash the stack, precedence lossage, overrun screw, leaky heap, leak.

--The Jargon File version 4.3.1, ed. ESR, autonoded by rescdsk.

Consider this C++ function:

void LeakyFunction() {
  int* i = new int;
  int* j = i;
  i = new int;
  delete i;

You see the problem? We allocated the memory for the initial i, but then we put it into j and forgot about it. The memory that's pointed to by j is never deallocated, and our only reference to it (the pointer j) is lost at the end of the function. If you call LeakyFunction() again and again and again, you'll eventually run out of memory and your program will crash.

The above is a trivial example, but it demonstrates how memory can be lost and nothing useful gained. Now scale this up to a full project with thousands of classes, and a few hundred leaks with bigger objects...

Log in or register to write something here or to contact authors.