DEV Community

Discussion on: Explain a "memory leak" like I'm five

Collapse
glsolaria profile image
G.L Solaria

To extend the lego block analogy and make the explanation unnecessarily more complicated for applications running with managed memory models (e.g. C# and Java)...

Imagine there is an invisible robot vacuum cleaner (i.e. the garbage collector) that runs around automatically picking up lego blocks.

Nobody is really sure when the robot will run and what it will pick up.

Sometimes it will not pick up some of the blocks even when you know it has run (e.g. when memory is pinned) and sometimes the block could be collected but the robot just doesn't feel like picking it up on that run.

To frustrate you further, when you go looking for leaked blocks, sometimes they are chained together and the root block actually stopping a bunch of other blocks from being collected is a block you least suspect.

I forgot to mention that it is also a Heisenberg robot so when you go looking for leaked blocks, the robot starts behaving differently.

So in conclusion, not only do you trip over the blocks in the dark but you might get super lucky and trip over the invisible robot vacuum too!