GameMaker Using an inventory without causing a memory leak

S

Spencer S

Guest
Everywhere I read, I see that not destroying DS_Grids and lists causes a memory leak that slows and eventually stops your game after a while. How do I use a ds_grid, which is populated with my inventory information, without causing a memory leak? I need to keep the grid active, because the grid is accessed whenever the player opens the inventory. And I obviously can't destroy the grid whenever the player isn't using the inventory, because then that wipes all inventory information. How do games get around this?
 
What that means is just that you need to delete it when you are done using it, that's all. The problem is only that they don't delete by themselves, as apposed to instances, whose variables, arrays, etcetera are all immediately removed from memory when you delete them. If you initialize a grid as a local variable on an instance and then destroy that instance, the grid will still be there. The memory leak occurs when you add grids and don't delete them when you no longer need them, especially if you restart the game without deleting them first, you'll end up creating duplicates. That's all, feel free to keep a grid around active the whole time, just remember that if you no longer want it active you have to manually delete it.
 
S

Spencer S

Guest
Ohhh, okay, that makes sense. Well I have some sort of memory leak in my game, but I don't destroy any items that include ds_grids, so that isn't it. I've heard (but I'm not quite sure) that using virtual keys can cause memory leaks as well. I've searched the manual but haven't really found any conclusive statement regarding that.
 
Sometimes it's because you have persistent rooms and you load more and more of them. That's to be expected (although persistent rooms aren't necessarily the best). Don't know about virtual keys. If it's not too bad, I wouldn't worry about it too much honestly.
 
Top