- Home /
how do you destroy a texture2d array ?
I have an update loop on the iphone that adds a texture to an array every .1 seconds. After the array fills up I want to destroy it and start over. I seem to be unable to destroy the texture2d array because memory on the iphone accumulates quickly and crashes the app. So how would I destroy these textures. I tried destroying them in a for loop var textures=new Texture2D[10]; //textures are put in each .1 seconds until full.
for(i=0;i<textures.length;i++){
Destroy(textures[i])
}
but that doesn't seem to work. Could someone explain the best way to destroy and delete the memory associated with a texture2d if it's by itself or in an array?
Answer by Eric5h5 · May 09, 2012 at 05:56 AM
Destroying Unity objects won't have any effect on memory, since they aren't part of Mono and aren't subject to garbage collection. You can use Resources.UnloadUnusedAssets. Also Unity objects are cleaned up when loading a new level.
and also dont forget to make the array null before calling Resources.UnloadUnusedAssets().
Answer by DavidStudio · Jan 21, 2016 at 10:03 AM
foreach (var texture in textures)
{
Texture2D.DestroyImmediate(texture, true);
}
Tested and seem to work fine!
Answer by perchik · May 09, 2012 at 05:01 AM
For the most part you're right, but try using Texture2D.Destroy instead of just Destroy
Destroy is a function of Object; doing Texture2D.Destroy has no effect, since it's just inheriting from Object anyway.
Your answer
Follow this Question
Related Questions
Memory issues 1 Answer
Can someone explain the destroy () command? 1 Answer
Textrue2D is not cleaned after Apply(false,true) 0 Answers
how do you delete variables or arrays? 3 Answers
Does Animator with Sprite Animation clip cause memory issue ? 0 Answers