As far as I can tell, the only way right now to signal that a struct is ready for cleanup is to remove whatever variable is holding it.@Alice Ok, so there is not a manual way to clean up structs? How do I signal that a struct is ready for cleanup?
Fanatrick's version is simply a function that returns a struct and would be no different in use than:@Fanatrick Hey, so what would calling that look like?
@Alice Ok, so there is not a manual way to clean up structs? How do I signal that a struct is ready for cleanup?
function vec2(_x, _y) {
return [_x, _y];
}
function your_function() {
...your stuff
return { x : _x, y : _y}
}
function your_function() {
...your stuff
return vec2(_x, _y);
}
my_struct = noone;
would signal for cleanup, or cause a memory leak var coords = scr_find_tile(params);
if coords != noone
{
var coord_list = ds_list_create(); ds_list_read(coord_list,coords);
var xx = coord_list[| 0];
var xy = coord_list[| 1];
ds_list_destroy(coord_list); coord_list = noone;
}
As far as I know, structs cannot cause a memory leak (assuming gc is on) but the manual says delete is more efficient clean up: "By default, structs with no further references in code will be garbage collected automatically in the steps following their use, but it is good practice to use this operator to flag them explicitly for the garbage collector to remove from memory at the very start of the following step, freeing the memory quickly and more efficiently." I'm not sure how much better it is though.Hmm I see, thankyou!
I wonder ifmy_struct = noone;
would signal for cleanup, or cause a memory leak
I'm not sure what you mean by this. Do you mean how do you use an array or struct returned by a function? If that is the case it would look like this assuming that your_function returned either a struct or array containing two values, x and y, where they are either named that, in the case of a struct or x is the first and y is the second value in the returned array:So what does this look like OUTside of the function, say in a step event where the function is called?
a_variable = your_fucntion();
//example use if a struct
x = a_variable.x;
//example use if an array
x = a_variable[0];
What was removed was 2D arrays, because now you can nest arrays indefinitely, and access them via chained array accessor, rather than 2D-array accessor.So I thought arrays were removed from 2.3, or was it just the array functions or something?
var _array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
, and then access it as var _arrayValue = _array[1][2];
._array[1, 2]
syntax instead (not sure if it would work correctly for this particular array declaration).function Vector2(_x, _y) constructor {
x = _x;
y = _y;
}