x


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?

more ▼

asked May 09 '12 at 04:26 AM

dansav gravatar image

dansav
373 104 131 154

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

For the most part you're right, but try using Texture2D.Destroy instead of just Destroy

more ▼

answered May 09 '12 at 05:01 AM

perchik gravatar image

perchik
347 2 4 9

Destroy is a function of Object; doing Texture2D.Destroy has no effect, since it's just inheriting from Object anyway.

May 09 '12 at 05:55 AM Eric5h5
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered May 09 '12 at 05:56 AM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

and also dont forget to make the array null before calling Resources.UnloadUnusedAssets().

May 09 '12 at 06:08 AM flamy
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x764
x354
x328
x116

asked: May 09 '12 at 04:26 AM

Seen: 1085 times

Last Updated: May 09 '12 at 06:08 AM