GameMaker Memory Leak - Stack overflow (how to properly delete a list?)

A

Adry

Guest
Greetings! I've been working on a system to house multiple dialogue triggers and to save them as they change. I finally believe I got it working-ish, (to save and load) - this is my process: I save a list, within my save function -
GML:
ds_map_add_list(_map, "Dialogue_flags", global.dialogue_flags);
| It works because reseting my game will give me the saved "dialogue trigger" on load, however..
As soon as I try to save again, I get this unfortunate fellow Stack overflow.. gml_Object_obj_save_interface_other_10

I'm almost positive it's the ds_map_add_list that is causing the error because it started showing up when I incorporated it.
I'm also assuming that it is a matter of deleting this "list" correctly as I heard if not done so properly it can cause a memory leak..

I've tried this: ds_list_destroy(global.dialogue_flags); but I still get the same error..?
Here's when I find myself a bit confused? I've looked up DS Lists on Yoyo docs, where I find:
  1. ds_list_destroy
  2. ds_list_clear
  3. ds_list_empty
  4. ds_list_delete
How do I know which to use, not to mention when to use it? I'm pretty new to all of this ds_maps and ds_lists but I'm trying my very best to wrap my head around it.. I'm also confused about maps! because with "ds_map_add_list" what exactly is going on? is it making a map of a list? does that mean I have to destroy it as a map? Just not sure how to approach this other than to reach out and hope some of you programming kings and gurus have any insight :) thanks for bearing with this most likely very rookie post. Cheers!

** 'should also mention that I'm saving with JSON-

warmly,
Adrian
 
Last edited by a moderator:

ophelius

Member
Before continuing, make sure you understand what ds_list and ds_maps are, what the difference is, how they are used, etc.
If you can't visualize your data and how it's organized, then you'll run into trouble.

A ds_list is a 1-dimensional collection of data. Imagine a street with a bunch of houses one after the other, each house contains stuff, and each house has an address.

A ds_map is a 2-dimensional collection of data. Imagine a grid, where each cell has a x and y coordinate. You can find any cell and what it contains by knowing the coordinate.

The data ds_lists and ds-maps can contain can be anything really: values, strings, other ds_lists, other ds_maps, etc.

So get acquainted with how to create ds_lists/maps, read the manual so you know how to add data to them, how to retrieve any data by knowing the address/coordinate, and how to properly destroy them when not needed anymore. Destroying a ds_list or map will destroy the contents of that structure.

Edit: In this post, I'm talking about ds_maps, but I got it confused with ds_grids. They are both different data structures, but I got them mixed up. ds_grids are what I was referring to.
 
Last edited:

chamaeleon

Member
As soon as you call ds_map_add_list(), the list you provide becomes owned by the map. You are no longer allowed to destroy it yourself, as the map will destroy it when it is destroyed. You might want to have a list dedicated to the map, for saving purposes, that is separate from your game state list.
GML:
var flag_list = ds_list_create();
ds_list_copy(flag_list, global.dialogue_flags);
ds_map_add_list(_map, "Dialogue Flags", flag_list);
...
ds_map_destroy(_map); // will also destroy the list that was stored in flag_list
 

TsukaYuriko

☄️
Forum Staff
Moderator
ds_list_destroy destroys a list and frees the memory it used.
ds_list_clear removes all elements from a list.
ds_list_empty checks whether a list is empty.
ds_list_delete deletes a specified element from a list.

ds_map_add_list adds a key-value pair to a map with the value being a list's ID, and this pair is then marked internally as a list so that it can be encoded properly by the JSON functions. It also causes the list to be destroyed when the map containing it is destroyed.
 

Nidoking

Member
Is it possible that you've added the same list to the map multiple times, or that the list contains a reference to itself, or to the map that in turn contains a reference to the list? That would cause infinite recursion and overflow the stack.
 
A

Adry

Guest
Is it possible that you've added the same list to the map multiple times, or that the list contains a reference to itself, or to the map that in turn contains a reference to the list? That would cause infinite recursion and overflow the stack.
Yes, I will have to look into that, 'cause I think you are on to something!
 
Top