What is a memory leak? (Part 1)
This is how it’s like to have a memory leak.
What is a memory leak?
Explanation Example
Imagine you have a swimming pool. But somewhere in that pool there is a tiny hole. Ok. No big deal. It’s hardly noticeable, but it is there. You can still swim ok – for the moment at least. No problems. But slowly and ever so surely, the water level starts decreasing, until it’s about ankle height. Now it’s getting ridiculous. You can’t do anything in water that is so low. That sucks coz now everything comes to a stand still. Or swim-still. You cannot do anything. And that’s a big problem. It’s the same with computers and memory leaks:
Memory Leaks in terms of computing
Imagine for a second that you are unable to remember anything - nothing at all. If a person asks you what your name is, or your mother’s maiden name, or your password (please tell me that your password is not ‘password’) you would not know. But luckily for you, you’ve filled up a room in your house with all this important information. In this room you promiscuously dumped files all over the floor. One such file might contain DOB info, or your SSN details, or your TFN number etc. etc. If someone asks you about that info, you would simply walk in the room and take out the relevant file.
So what is the catch with this room?
The catch is that you have limited space in the room. Anything you don’t need should be disposed of. A garbage collector comes by your front door and asks you to hand over any files in the room which the garbage collector knows about, and which he feels you no longer needed.
The important point here is that the garbage collector needs to know about things in the room before he can trash them. If he doesn’t know about it, well guess what: (i) he’s not gonna ask kyou to bring those files out, and (ii) those files are gonna keep accumulating in that room till there is no more space left.
So basically, unless you have a very good reason: you need to get rid of any files you no longer need. If you don’t do that, then basically you’re creating a problem for yourself, especially down the line.
What if you add things to your room without telling the garbage collector?
You’ve decided to take up the piano and have dumped a Steinway in the room. (I’m not on commission btw).
What a beautiful gaddam instrument. But there’s not much space left – and you haven’t told the garbage collector. You practice for a couple of days and then find it tiresome – so you give up but still leave the piano in your room.
The problem is that it takes up a lot of valuable real estate. The garbage collector comes by every week but never asks for the piano because he doesn’t know it exists. You’ve decided to add it in there by yourself without telling him. Accordingly that piano could be in there for much longer than what is necessary. Taking up valuable space. You run the risk of running out of space – and that can cause problems.
That is the basic concept of a memory leak: it means that you have stuff in there which you don’t need. Accordingly you ought to dispose of things when you don’t need them – especially if the garbage collector does not know about.
I will outline nuances of this concept in my next post tomorrow.