DEV Community

Cover image for Explain a "memory leak" like I'm five
Peter Kim Frank
Peter Kim Frank Subscriber

Posted on

Explain a "memory leak" like I'm five

Cover Photo via Unsplash

Latest comments (26)

Collapse
 
polterguy profile image
Thomas Hansen

A piece of used memory with no pointers to it. It's the equivalent of locking one of your drawers in your cabinet for then to flush the key down the toilet. The drawer is locked and hence you've got "one drawer less", but you can never access or modify what's inside it ...

Collapse
 
amit2908 profile image
amit2908

When two person become strong friends of each other and none of them wants to go away from each other. Then they reserve some time and space for each other, which is protected by both of them.
To break their friendship you have to make one of the friends as weak friend, so that the relationship between them becomes weak from one side and can be broken.

Collapse
 
tonnytg profile image
Antonio Thomacelli Gomes

When you have a car, and you run 999.999miles when you complete more than one mile, you leak... 000.001

Collapse
 
siddharthshyniben profile image
Siddharth

Imagine the computer is a hotel, and programs are people coming to the hotel, and the rooms are memory. So, programs rent rooms (memory) and use them. Later, they can leave the room (memory) so that others can use the room (memory).

A memory leak happens when an person (program) leaves the room without telling anyone. Now, that room (memory) is locked there, and others cannot use it because the hotel thinks that someone else is using it. This is a memory leak.

Collapse
 
siddharthshyniben profile image
Siddharth

Some OSs are smarter than others, and figures out that memory is not used and clears the memory and kicks out your program anyways. But some OSs like Windows, just keep asking 'do you want this memory anymore?'.

Collapse
 
hasnaindev profile image
Muhammad Hasnain

You're not five ;_;

Collapse
 
sinewalker profile image
Mike Lockhart

A memory leak is like a five-year-old who won't clean up their room.

If you don't clean up your room, you will never find anything, and your room will also be to cluttered to dump anything more.

Collapse
 
zkwsk profile image
Zaki Wasik

But "daddy not being able to walk around the house" is an externality. It's something caused by the 5 year old, but it is daddy who takes the cost. My 5 year old self would consider a house with floors covered in Lego the absolute ideal place to be.

Collapse
 
kampouse profile image
Kampouse

Its like leaving lego blocks but daddy cant pick them up and they keep stacking up until you cant walk 🥲

Collapse
 
jaymales profile image
Jay

A memory leak is like eating food that you can't poop out. You keep eating it until you it fills you up completely and explode.

Collapse
 
aminmansuri profile image
hidden_dude • Edited

I couldn't come up with an explanation for a 5 year old, but here's one for a baby:

You have 2 hands. If you want to pick up something you have to make sure one of your hands is empty. If you use up all your hands and forget to put something down, then you won't be able to grab things to put in your mouth.

Your computer has many many hands, but if you forget to empty the hands you'll eventually run out.