- Home /
How to delete new'd arrays?
I have an array I create thusly:
var room:roomInfo[,,];
room=new roomInfo[5,5,5];
What's the deleting syntax? Simply doing delete room;
or delete room[,,];
doesn't seem to work. After deleting it I need to do this:
room=new roomInfo[10,10,10];
Seems like a ridiculously simple question but I get confused about these things and forget, and I couldn't find anything on Google (because I couldn't work out what to search).
Answer by Clonkex · Jun 01, 2015 at 07:35 AM
My question was answered very well on this Stack Overflow page that I posted when I could see I wasn't getting anywhere on UA.
The essence of it is that if I do room=new roomInfo[10,10,10];
, the old data (the old array) referenced by the room
variable will no longer be referenced by any variable and will be deleted from memory at some point by the automatic garbage collector, a feature of JavaScript.
This is correct. The magic of a memory managed framework is you can just abandon references and let the garbage collector deal with it. Don't do it all the time, GC is not free. But its there.
In code that is
int[] intArray = new int [5];
intArray = new int[10];
Nothing needs to be written in between.
Answer by Crystalline · May 31, 2015 at 10:12 AM
Can use room.RemoveAt(index int). Or room.Clear ().
Question updated. I need to properly delete the whole array, not just clear its data. How would I do that?
@Crystalline To resize the array manually, as per the OP. Is that so strange?