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

567 viewsOtherTechnology

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

In: Technology

18 Answers

Anonymous 0 Comments

Oh seem’s like I’m first?

Imagine you have a shooter game. When you shoot a shot, you create a new entity “shot”, and it should travel and collide something or dissapear.

But you made a mistake! You forgot to delete the entity! So the more shots are shot during gameplay, the more and more and more and more entities continue to exist. Each entity may be a few kilobytes of memory, but if they’re never released, they keep gnawing at your memory.

Anonymous 0 Comments

If a program is working properly, it will gain permission to use a portion of random access memory (RAM), store info at that address, and then release the address when done, making it available to other programs. A memory leak is when the program fails to release the address and just keeps requesting more portions of RAM. This slows down the computer as it runs out of resources to share amongst all programs.

Anonymous 0 Comments

Your RAM is constantly storing and over-writing data. When a piece of data is no longer needed, it will free up that space so new data can be over-written. So, for example, a game might load the textures you need for a certain piece of the map, and then when you move on it forgets the part of the map you don’t need anymore.

A memory leak is a flaw in the code that writes new memory but never releases it. So going back to my example, the game is loading the portions of the map you need, but never forgets the parts of the map you don’t need. It keeps storing this data in its “active” memory, expecting to put it to use in the near future.

Eventually, like a leak in a boat, the memory is so full of irrelevant data that it no longer has room to write the new data that you actually do need. So all of your processes slow down until it all just crashes.

Anonymous 0 Comments

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.

Anonymous 0 Comments

“Hey everyone, I’m using the car”

*hours later*

“you’re not in the car? I was waiting for it”

“oh yeah I forgot to tell you I was done”.

Some part of a program grabs some memory to use it, nothing else can use it, then ‘forgets’ to release it. A mistake by the developers. Gradually all the memory gets claimed, and the game crashes when something needs some memory and there “isn’t any”.

Anonymous 0 Comments

It’s a common software bug where the memory(RAM) is allocated by not freed. And it remains wasted and never repurposed.

A good sign of memory leaks is when a game seems to use a lot of RAM for no apparent reason and the only way to fix it is to restart the game

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.

Anonymous 0 Comments

It isn’t specific to video games, but rather computing in general.

Basically, when a program saves data, there’s a place it’s designated to save it to. If that area is full, it’s supposed to either find data that can be deleted in that area to be replaced, or fail to save the data at all.

A memory leak is when instead of doing either if those, it just saves the data in the next spot in data that it thinks it’s allowed to save in, but actually, it overwrites important data that is supposed to be outside of that designated zone.

Imagine our memory has 10 spots for data, numbered 1-10

Slots 9 and 10 hold important information that isn’t supposed to be changed

Slots 1-8 hold data that changes all the time, and start empty

The program goes off, doing things and it fills slot 1, then 2, and so on. Once it fills slot 8, without emptying any other slot, we are in danger of a memory leak. If the program doesn’t check if it’s about to fill slot 9, where it’s not supposed to be, it will just fill that slot, overwriting the data that it’s not supposed to. Everything will work fine until the program needs the data that’s supposed to be in slot 9. It instead loads the data we put there, so the program will take the wrong action because it read the wrong data.

It could also encounter an issue if it fills slot 10, and then tries to fill slot 11, which doesn’t exist. If this goes on long enough, it can overwrite something critical to the system’s operation

Anonymous 0 Comments

Imagine you lose $1 down the side of a sofa. You still have $1, but its inaccessible to you. You might want to exchange that dollar for some snacks but you cant because you dont know where it is

This is (sort of) like a memory leak in software. The program stores something (like a number) in the computers RAM, but at some point (due to programmer error) it forgets where in RAM it put that number. The number is still there, taking up space, but the program cannot free the space back up because it doesnt know where the number is. If this happens enough all the RAM will be consumed and the program will crash

Anonymous 0 Comments

In general memory leaks tend to occur more frequently in ‘lower level’ languages…ie, those ‘closer’ to the hardware, like assembler or C.
These are the languages more likely to be used in video games because of the necessity for speed and efficiency.
Modern high level languages usually have some sort of garbage collection built in which reduces (but not eliminates) memory leaks. These tend not to be used for video games as they are generally slower and, perhaps more importantly, can have unpredictable performance. Automatic garbage collection can disrupt a game by kicking in at inopportune times.