It’s not specific to video games, but can happen in all software that uses dynamic memory allocation (which is almost all modern software).
Basically, the program has to ask the operating system for memory every time it wants to store something. The operating system will then reserve some space in your computer’s memory and tell the program that it can use it. This space now belongs to the program, until the program ends or until the program tells the operating system it doesn’t need it anymore.
A memory leak is when through some bug in the programming the program doesn’t tell the operating system to release some of its reserved memory when it’s no longer needed. When that happens repeatedly, the amount of reserved memory can continuously grow throughout its lifetime and use up all of your computer’s memory.
**To give an ELI5 analogy:**
Imagine every time you buy furniture you store your old furniture in a storage facility until you can sell it. You go to a storage unit service and rent a new storage unit. You put your old furniture in it. A few weeks later you find someone who buys your old furniture and now the storage unit is empty. However, you forget to tell the storage company that you don’t need the unit anymore! Next time you buy new furniture, you again rent a new storage unit, and once you sold the old furniture you again forget to tell them to cancel your rental contract. Now you already have 2 units that are empty but reserved for you. Nobody else can use them, and you still get charged for them.
If this happens many many times, at some point maybe the entire building full of storage units belongs to you – or at least all of the free ones. No other customers can use the storage service anymore, because unbeknownst to you, they are all assigned to you, even though you don’t use them. The only way to free them is if you die (analogy for: the program ends) because that’s when your rental contracts automatically expire.
Latest Answers