2

I am a hobbyist programmer, bit of a stickler for terminology, currently learning C and recently came across the concept of Memory Leak. Now, I do understand what it means. Dynamic memory allocated to a program is not returned by the program.

But where does the term 'leak' come from? Is it coming from the fact that other programs cannot access the dynamic memory, since one is already hogging it, and thus total memory available from the OS to the heap is reduced and therefore "leaked" to the one hogging it? Basically, are we see the memory leak from the OS's perspective? And therefore saying that it is leaked to the program?

11

Look at it at the other way, from the system perspective. You have a giant pool of free memory (free ram memory) where different programs can make use of. But all of their used resources should be returned sooner or later, or at least being used the entire time. When you no longer need it you should return it to the pool of free memory. Applications that keep asking for memory from the pool but never return it when they're done using it, cause a leak in the free memory pool until they've stopped. The program is a leak to the pool of free memory and I think from that perspective the term memory leak is a correct naming.

So we'll see the leak from the system's perspective.

5

It's fairly self explanatory. The application is diminishing system memory, this memory is allocated but not useful to running code. This is analogous to a physical leak as the system memory is slowly lost (like water from a leaky bucket) to useless allocation. I'm not sure about the etymology, but it a fairly obvious analogy, so I doubt there is a clear origin.

1

There are two theories about where the term "leak" and other liquid based analogies for memory originated.

In the ENIAC, and in very old systems, memory was stored in circulating mercury, something called a mercury delay line. Information was represented as a charge in a portion of mercury that circulated around tubes. The charge was read when that part of the mercury passed by detectors (BTW, this is why ENIAC could only use half of the memory... see below).

In this case, a memory leak is quite literal, and fairly hazardous.

The other theory comes from the mainframe days. Memory was shared between any running jobs and was called a "pool" of memory after things like motor pools, secretarial pools, and similar. When a job (program) caused memory to become inaccessible, that memory "leaked" out of the pool.

Side Note: Regarding ENIAC memory. ENIAC had a central computing engine with mercury delay line memory in cabinets on both sides. The problem is that accessing the memory requires knowing the timing, and that is dependent on temperature. It was not possible to maintain a consistent temperature in both memory cabinets and there was no effective way to adjust a program based on which cabinet was being used. The result is that ENIAC usually ran on just half the memory.

  • Simple: cool the memory to -40. Now it is solid-state memory! – user251748 Dec 8 '17 at 17:41
0

Just think about a programs memory usage like a closed water cooling system in a car:

The water is pumped out of the reservoir to the parts that need cooling, then on to the radiator, and returned to the reservoir. In this way the same water molecules are used over and over again, for days, months, years. As long as the system is perfectly closed, it can run virtually forever. This corresponds quite nicely to the ideal use of memory by an application: All memory is returned to the reservoir when it's not currently needed, so that it can be used over and over again, allowing the process to run forever.

Now, what happens when you have a leak? The water/memory is lost for reuse. You don't really care where the water/memory is gone to. If it's lost from the closed system of pipes / known memory regions that will eventually be returned to the reservoir, the reservoir will deplete overtime. The amount in the reservoir will drop over time until there's not enough left to ensure proper operation. Again the analogy is pretty good: The car looses cooling water for reuse, the application memory. The car will eventually overheat, the application crash.

I honestly don't know whether this is the analogy that the people who coined the term "memory leak" had in mind, but I'd wager that it's pretty close. After all, memory was a really scarce resource in the early days of computing when the term was coined. It's like running a cooling system with only a really minimal reservoir: Any minor leak will lead failure in almost no time. So, the reuse of memory had to be pretty perfect to allow successful operation over any extended period of time.

protected by gnat Apr 16 '16 at 8:59

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.