Cleaning memory after loading a new texture

Hi,

I work at a big project with more than 350 textures. And only like 20 should be in the memory.
I have problems to delete the already loaded textures out of the memory.

var mainTextureTemp = new Texture2D(Global.photoSize, Global.photoSize);
mainTextureTemp = UnityEngine.Resources.Load(sourceLocation, Texture2D);
//DestroyImmediate (Plane.renderer.material.mainTexture);
Plane.renderer.material.mainTexture = new Texture2D(Global.photoSize, Global.photoSize);
Plane.renderer.material.mainTexture = mainTextureTemp;

This script blows up the memory (by 70 MB) every time I run it.
If I uncomment the commented line I get an error message:
“Destroying assets is not permitted to avoid data loss.”
Though the memory is (basically (like 5 MB still seems to stay every time)) cleaned then…

How I clean the memory proper ?

BTW… I noticed the same behavior with:

www.LoadImageIntoTexture(renderer.material.mainTexture);

what is your picture of? :?

hey i just read the part about blowing up memory. sweet! hey, can you tie in special effects and a voice so it will say, “Hey, you just lost alot of mem. would you like to save” while it shows an explosion? :smile:

It WAS a joke.:o

Heh… :wink:

This ?
<-----

It’s from the movie “Judge Dredd”.

-Could someone help me with my question ?
I read somewhere that there is currently an issue with the memory and new textures which should be fixed in the next build…
True ?

You can use the DestroyImmediate function on textures loaded with the WWW class.

Thanks for the answer Joachim.

What about Resources.Load() ?

I tried to fix the error. No luck so far. Any hints or workarounds ?