• 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!

Memory managment ds_map

C

Carpe Zythum

Guest
I need some thoughts on memory managment for ds_map in Game Maker.
I've created a map of maps in a global variable global.research.
And then I used my custom scripts to generate all the data for research.
But I have a problem with this, the research tree variable needs to exist for the whole game, and in the obj_research_controller ( persistent object )'s destroy event I've used a custom script to free all the memory I've allocated. ( It's a lot of memory, the DS map holds the whole tree, and in each individual tree I have a list object that holds the children of that research. I needed to do this to simulate a binary tree data structure ).
So, I want all that memory to be free when the user exits the game, but, the destroy event of my obj_research_controller doesn't get called when I press the "X" button of my game, or alt+F4.
When you exit through the menu, the script is called, since I destroyed that object manually when the user exits the game that way.
My question is: Does game maker free my allocated resources via a system when I press the "X" or alt+F4, or should I implement a custom system to take care of that event.
PS: My game is for Android aswell, so I don't want a memory leak to exist.
 
C

Carpe Zythum

Guest
Here's all the code of my research system by the way:
Code:
/// ds_create_research( name, local_name, sprite, parent ) : research_id
// TODO: add a check to see if all the arguments are given

var name = argument0;
var local_name = argument1;
var sprite = argument2;
var parent = argument3;
var isRoot = false;
if(parent == false) {
    isRoot = true;
}
// Start with no children
var children = ds_list_create();

var research_id = ds_map_create();
ds_map_add(research_id, "name", name);
ds_map_add(research_id, "local_name", local_name);
ds_map_add(research_id, "sprite", sprite);
ds_map_add(research_id, "root", isRoot);
ds_map_add(research_id, "children", children);
ds_map_add(research_id, "researched", false);

// Returns a hash map of all the values of this research
// This is a mimics the Object type in OOP functional programming languages
// like javascritp
return research_id;
Code:
/// ds_create_research_tree() : research_tree_id
// This script is used to inistialize the research tree,
// TODO: Currently, the research tree is stored in memory troughout the whole game
// If it uses too much memory, read it from a file insted

// Initialize all the research entries
// Research tree root
var basic_materials = ds_create_research("basic_mat","Basic Materials", spr_grass, false);

// Research tree branches
var strange_goo = ds_create_research("enemy_goo","Strange goo", spr_weed, basic_materials);
var metal = ds_create_research("metal","Metal", spr_rock, basic_materials);

// Register all the children
ds_research_add_child( basic_materials, strange_goo);
ds_research_add_child( basic_materials, metal );

// Make the research tree
var tree = ds_map_create();

ds_map_add(tree, ds_map_find_value(basic_materials, "name"), basic_materials);
ds_map_add(tree, ds_map_find_value(strange_goo, "name"), strange_goo);
ds_map_add(tree, ds_map_find_value(metal, "name"), metal);

return tree;
Code:
/// ds_research_add_child(research_id, child_id )
// Adds the research to the children
var research_id = argument0;
var child_id = argument1;

var list = ds_map_find_value(research_id, "children");
ds_list_add(list, child_id);
 
E

elementbound

Guest
If you only want to free that data when the user exits the game, you shouldn't worry about that. Once your application is closed, all memory allocated by it is freed. This is done by the OS.
Please note that this does not necessarily apply to game_restart().

Also, try the Game End event instead of Destroy.
 
Top