What is a Memory Leak?

Written By: Neilvert Noval - Sep• 29•11

Article Category: Geek

My German officemate, Harold, is asking for my opinion on his software problem. I’ve looked at the logs and said, “It’s a memory leak.” So what is a memory leak? This drives me in writing this article so I can explain it also to the readers in a simple manner as to what memory leak is.

It cannot be avoided to expose technical stuffs here. But as much as possible I would avoid deep topics so as to cater non-technical readers.

So what indeed is a memory leak?




Basics

You can see several programs in your computer. Every time a program is run (or launched) it consumes computer memory. However, your computer memory is limited (say 4 Giga Byte of memory, unlike your hard disk which can have as big as 1 Terra Byte capacity). Get the idea so far? So if a software program consumes a memory, and that memory is limited, then that would mean that each program must consume as little memory as possible so as to give enough memory for the other programs.






Imagine this. If your Calculator program can consume all of your memory, that would mean you can not anymore launch another program (like NotePad or Solitaire) because the Calculator is eating all of the memory. So each program must be prudent enough to consume as little memory as possible to give way for other programs.

Click image to enlarge

The Leak

When a program is launched, it allocates its own memory (as described previously). This allocated memory can be used in many forms, like a temporary storage for the results in a Calculator application. Or can be use to store what button the user press, etc.

But not only that. When the memory reserved for Calculator result is not any more used, or if the user do another new calculation, then it is fitting to release the allocated memory. A program must release that memory when not in use. This is so that the released portion of memory can be used by other programs. Each program must see to it that the allocated memory must be released (or freed) if it is unused.




 

When the program failed to release the memory, the memory portion (the allocated one) will remain as though it is used even if it was not used by the program. And this portion of memory will never be used by other programs, therefore it’s a waste of memory. And that is Memory Leak! (*thunder strikes!*)

Analogy

To make memory leak even more clearer, we can relate this to a real world situation.

Here’s the scenario:




Memory Leak Cartoon

Click image to enlarge

 

  • First, a person enters the public bathroom. (as though the Program started)
  • The person is using the bathroom. (the program is allocating a memory portion. Bathroom = Memory)
  • The person poops. (this is like as though you are using your program to your desire. Gross!)
  • Other people cannot use this bathroom because of the grossly mess. (this memory portion is unused because the program failed to release/relinquish the memory)

 And that is Memory Leak.




FacebookLinkedInBlogger PostWordPressPinterestDiggRedditEmailTumblrStumbleUponShare

Related Posts:

The author would love to read your comments.
Comments will appear once approved by the moderator.

One Comment

  1. papaleng says:

    Very interesting article with useful information. Learned some new facts here.

Leave a Reply

Your email address will not be published. Required fields are marked *


(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>