• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Do you need to delete a ds_grid when you insert it into a ds_map?

jakaloy

Member
I'm making a server with udp so I need to save clients ips and stuff. I'm inputting that info into a ds_grid, which is then inserted into a ds_map with a key of the match number. After I input it into the ds_map do I need to use ds_grid_destroy()? I'm pretty sure that that isn't needed, but I want to be 100% sure because this is for a server and the last thing I want is a memory leak in it.
 

TsukaYuriko

☄️
Forum Staff
Moderator
It's not only not needed, but detrimental, as inserting a grid into a map doesn't copy the grid's contents into the map. It inserts its ID, which can be thought of like a reference. If you destroy the grid after inserting it, you destroy the only copy of the grid that exists, and therefore lose all data it contains.
 

jakaloy

Member
It's not only not needed, but detrimental, as inserting a grid into a map doesn't copy the grid's contents into the map. It inserts its ID, which can be thought of like a reference. If you destroy the grid after inserting it, you destroy the only copy of the grid that exists, and therefore lose all data it contains.
Thanks! So if I understand correctly once a grid is inserted into a map, after any further changes to the grid I don't have to that again. For example, if I want to add instance ids to the grid, after the change, I don't have to use ds_map_add_value anymore, but when I reaccess the grid from the map, the ids will be there.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Correct. Since you'll be storing the grid's ID in the map, not a copy of its contents, any changes you make to the grid using the original variable that holds its ID will be applied to the same grid referenced by the entry in the map (since they refer to the same grid).
 
Top