What is a “memory leak” in terms of video games?

571 viewsOtherTechnology

What is a “memory leak” in terms of video games?

In: Technology

18 Answers

Anonymous 0 Comments

Brief primer: storage drives (hard disk drives and solid state drives) can hold a lot of data for cheap and that data stays when power goes out; but, it’s slower to recall data. Random Access Memory is super fast, has a ton of connections in and out; but, it’s too expensive to make your entire computer out of RAM and, probably more importantly, it doesn’t hold data when the power goes out. Programs install to the permanent storage and then as they’re needed, your computer pulls that data from storage (slowly) and puts it into RAM to be used (quickly).

Since RAM is limited, your computer is stingy with it and only gives it to programs as they need it. The computer assigns the program some RAM, and the program can request more. When the program is done with the RAM, it sort of gives it back for other programs to use. The program tells itself that it’s done with the RAM, and that it’s been given back, so don’t use it anymore. That needs to happen – if a program tries to use the RAM that’s been assigned to another program, it causes problems. It can also be a significant security risk, since it gives programs access to other programs without permission.

So, CPU gives a program some RAM; that program uses the RAM until it’s done. The program notes to itself that it can’t use that RAM anymore, then tells the CPU it can give the RAM to someone else. All of the programs running on your computer go through this process in order to share RAM, and your computer prioritizes certain programs when RAM is too limited. Typically, whatever program you have open and active gets the highest priority, especially games.

A memory leak is when the program stops using the RAM, notes to itself that it’s done and can’t use it anymore, but forgets to tell the computer that it’s done. The computer can’t assign that RAM to any other program, because as far as the computer knows, the first program is still using it. That program, though, *isn’t* using it. When that program needs more RAM again, it sends a new request for more RAM. The computer gives it more RAM, the program uses it, stops using it, but again forgets to actually tell the computer that it’s done.

As time goes on, the program keeps requesting more RAM and the computer keeps giving it more RAM, while the pile of unused RAM keeps building up because the computer still does not know that the program is done with it. The computer still believes that the RAM is being used. Since the game is high priority, the computer keeps giving it RAM while taking RAM away from other programs, forcing them to run slower and slower. Eventually, all the RAM that can be given to the game has already been given to the game, and even that starts to slow down because it doesn’t have any RAM to use.

Most computers have tools to detect memory leaks and take RAM back from programs that aren’t using it, but they can’t be perfect because, as I mentioned, a mistake can be a major security risk. The only other way to stop the leak is to shut the program down completely so that the computer can see that, oh it doesn’t matter if that program never officially gave the RAM back, that program is ended so all of its RAM is up for grabs again.

You are viewing 1 out of 18 answers, click here to view all answers.