May 28, 2014

When Memory Leaks

Filed under: Main — admin @ 12:01 am

While my favorite PC term happens to be dump, I also hold some fondness for the term leak. Specifically, a memory leak.

Suffering from some leaky faucets recently, I got to thinking about all types of leaks.

As an example, faucets leak. When plumbing goes awry, water goes everywhere. It’s a mess.

Yet, when electricity goes awry, it doesn’t leak, does it? In fact, the scary thing is that electrical malfunctions can cause fires. I suppose that’s a type of “leak,” although the power lines aren’t funneling flames of death all over town. In fact, electricity may leak out of open sockets and we’d never know it.

All that nonsense aside, a computer memory leak is something you definitely know about. While they aren’t as common as they once were, such leaks are entirely possible.

Basically, a memory leak is a bug. It happens when programs don’t keep track of how they use memory. The “leak” occurs when the program keeps asking for more and more memory, or it keeps consuming memory until capacity is reached. Then the entire system comes crashing down.

Memory leaks were more common back in the Days of DOS. Back then, a single program took control over the entire computer. Memory wasn’t dished out, neither was memory protected. Instead, the operating system (DOS) said, “Hey! Here is all the hardware. Do your worst.”

Somewhere deep in the code, the programmer forgot to dot an I or cross a T. A request was made for a chunk of memory over and over again. Gradually, all memory would disappear.

Memory leaks went undetected as long as the program had room to bloat. So a small program, say a text editor or utility, could run safely, leaking memory like a sieve, and you’d never know. The program would quit, and memory would be released.

When a memory-leaking program ran longer, the problem became more noticeable. Eventually a Memory Error would occur and the system crashed.

You might think that with today’s computers, with their greater memory capacity, it would take even longer to discover a memory leak.

Not so!

Modern operating systems allocate memory under guidelines more strict than Edna the Lunch Lady doles out the cherry jello. Programs that violate the rules, leaking memory like a dripping faucet, are contained. The operating system catches the leak, halts the program, and that’s that.

Command line programs that leak generate a Segmentation Fault error. (If you’re a programmer, I’m sure you’ve seen a few of those.) Other programs simply shutdown with a generic operating system message, such as “The program `Blorfus` has stopped working and will be shut down.” That message is bland, so the problem might not be a memory leak, but it could be.

Can you fix a memory leak? Nope. Only the programmer can address the issue. So put away that pan and never mind the towel. Memory leaks may happen, but fortunately they’re far less frequent than in days past.

2 Comments

  1. “You might think that with today’s computers, with their greater memory capacity, it would take even longer to discover a memory leak.

    Not so!”

    Of course, you can always abuse malloc by putting it in a while loop…

    Comment by linuxlove — May 28, 2014 @ 7:02 am

  2. Pointers are the more likely culprit. Buffer overflows. That stuff.

    The last memory leak I had was with a recursive routine. I ordered the statements wrong, so the function kept calling itself over and over again, when it was supposed to go in a sequence. It took me forever to figure out why it was doing that. The code ran and ran. Only after a few seconds did the Segmentation Fault appear.

    Of course, back in the old days, it would have generated a Stack Overflow, which is a more specific message.

    Oh, but I do go on.

    Comment by admin — May 28, 2014 @ 7:15 am

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.


Powered by WordPress