- Home /
how do you delete variables or arrays?
How do you delete or destroy variables or arrays in unity javascript?
Is there a delete? I tried using Destroy but it only works with objects and components. Do I just rewrite or declare the variable again?
Answer by Berenger · May 09, 2012 at 04:49 AM
If I'm wrong, please someone correct me.
In .net a variable exist only as long as it is referenced somewhere, unlike languages like C++ where you have to delete pointers and co. So if you're concern with memory leaks, just make sure to affect null to variables you don't need anymore.
You are correct. Unreferenced value types and orphaned parts of the heap will be garbage collected automatically.
You mean just set the array to null like textures=null; if textures=new Texture2D[10]?
Answer by Drakestar · May 09, 2012 at 01:42 PM
By the way, C# does allow you to manually define blocks of code that should be garbage-collected immediately after use with the "using" statement. (Not to be confused with the using directive for namespaces that you always see at the beginning of a file!). http://msdn.microsoft.com/en-us/library/yh598w02%28v=vs.80%29.aspx
Answer by simeonradivoev · May 09, 2012 at 04:24 PM
If you are Using a javascript array
for (var i:int = 0;i < array.length;i++){
array[i].pop();
}
if you are using a build in array of number you just need to set them to null
for (var i:int = 0;i < array.length;i++){
array[i] = null;
}
and i don't think you can destroy variables, just change their values.