Arrays are garbage collected and can't cause a memory leak. As long as there is no reference to an array, it'll be removed automatically. When you set the value of an array that has been passed into a script like this:
Code:
var _array = argument0;
_array[0] = some_value;
GM copies the array. This doesn't create a memory leak but it might not be very performant. In general with arrays passed into a script:
Code:
var _array = argument0;
///_array will no be a copy of the array passed into the script
_array[0] = some_value;
///will directly modify the array passed into the script
_array[@ 0] = some_value;
///not wrong but doesn't do anything different
some_value = _array[0];
some_value = _array[@ 0];
Using the @ accessor for arrays outside of a script is the same as not using them. In other words the only time you need to use the array accessor is when you have passed an array into a script and want to modify (not read) the array inside of the script without copying it.
There is, as far as I know, no difference between using data structure accessors or using the GML functions. It is pure convenience.
You could theoretically handle deleting lists with some type of persistent object, but it would be hard to do correctly. The best way to delete data structures really depends on what you're doing with them, but the following two rule will cover most situations:
- destroy the data structure in the same 'place' you created it. So, if it is an instance variable, use the cleanup event of the object that is creating it. If it is a local variable in an event or script destroy it at the end of the event or script it is in (take special care with scripts and events whenever you are using keywords like return, exit, break, continue or anything that would end the event or script immediately). If it is a global variable, you probably don't need to destroy it as presumably you would want it in existence for the entire game (if not, it probably shouldn't be global).
- after assigning a data structure to a variable never assign anything to that variable again.
Both of the above rules can be broken, but if you're just learning how data structures work, you probably shouldn't. The one main exception to the above is lists and maps stored inside eachother and marked as such, but if you aren't using the JSON format or that doesn't mean anything then you're safe to ignore it.