GameMaker Does deleting a data structure full of data structures delete all the data structures with in it?

P

Paradox

Guest
Does deleting a data structure full of data structures delete all the data structures with in it?
 

GMWolf

aka fel666
No, unless you used lists and maps and used ds_map_add_list and the other similar functions
 
Last edited:
is this the correct way to delete a ds_list which contains ds_list in it?

Code:
//creating a dslist which holds other ds list
dslist = ds_list_create();
for(var i = 0;i<10;i++)
{
    node = ds_list_create();
    ds_list_add(node,i);
    ds_list_add(dslist,node);
}
//deleting the dslists in the ds list
for(var i = 0;i<ds_list_size(dslist);i++)
{
    ds_list_destroy(dslist[| i]);
}
ds_list_destroy(dslist);
 

Mert

Member
I was wondering the same for the following example;
Code:
var a = json_decode(myJsonString);

var data = a[? "data"];
var map2 = data[? "map"];

ds_list_destroy(a);
do data and map2 variables own their own map?
 
H

Homunculus

Guest
is this the correct way to delete a ds_list which contains ds_list in it?
This is a way to do it, looks correct to me. The alternative as suggested by GMWolf is to mark the internal data structures as such (using ds_list_mark_as_list in this case) and delete only the outer one.
 
This is a way to do it, looks correct to me. The alternative as suggested by GMWolf is to mark the internal data structures as such (using ds_list_mark_as_list in this case) and delete only the outer one.
ok this is has the same result as the previous code but I used ds_list_mark_as_list which makes it looks a bit smoother.

Code:
//creating a dslist which holds other ds list
dslist = ds_list_create();
for(var i = 0;i<10;i++)
{
   node = ds_list_create();
   ds_list_add(node,i);
   ds_list_add(dslist,node);
   ds_list_mark_as_list(dslist,i)
}

ds_list_destroy(dslist);
what happens with node? does this cause any memory leaks? do I have to clear it somewhere? or does the ds_list_destroy(dslist) take care of it due to the ds_list_mark_as_list()?
 
H

Homunculus

Guest
The nodes are deleted along the main dslist due to being marked. No memory leaks that i can see in your code.
 

chamaeleon

Member
I was wondering the same for the following example;
Code:
var a = json_decode(myJsonString);

var data = a[? "data"];
var map2 = data[? "map"];

ds_list_destroy(a);
do data and map2 variables own their own map?
No, you're just assigning numbers to the variables.
 
Top