I am getting WWW images onto some cubes from a google image search and the memory goes above 1gb after 20 pics, and when i stop Play the memory only goes back to 900mb until i restart the Unity Editor.
I have checked all the forums for solutions and have tried about 10 different solutions.
Can you find a logical reason why www.textures are being lost inside memory and i can’t delete them?
var tex2d[] = new Textre2D[100];
var ZZ =0;
var foundpics = 0;
function imgcube( imgURL : String , cubename : String ){
//function called inside loop for 10 imgURL's
var loopbreak = 0;
var www = new WWW(imgurl);
yield www;
ZZ ++;
tex2d[ZZ] = www.textureNonReadable;
while( loopbreak < 10 )
{
yield WaitForFixedUpdate();
loopbreak ++;
if( www.isDone == true )
if(tex2d[ZZ].width < 256 || tex2d[ZZ].height < 256)
{break;}
else
{
foundpics +=1;
var cube = GameObject.CreatePrimitive( PrimitiveType.Cube ) ;
cube.GetComponent(Renderer).material.mainTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);
cube.transform.position = Vector3(-4+foundpics%10,Mathf.Floor(foundpics/10),-20);
www.LoadImageIntoTexture(cube.GetComponent(Renderer).material.mainTexture);
//cube.renderer.material.mainTexture = tex2d[ZZ];
//Destroy(cube);
(cube.renderer.material.mainTexture);
//Destroy(tex2d[ZZ]);
tex2d[ZZ] = null;
Resources.UnloadAsset(tex2d[ZZ]);
DestroyImmediate(www.texture);
DestroyImmediate(tex2d[ZZ]);
var op : AsyncOperation = Resources.UnloadUnusedAssets();
while (!op.isDone) yield WaitForFixedUpdate();
System.GC.Collect();
www.Dispose();
Resources.UnloadUnusedAssets();
break;
}
if (loopbreak >10) break;
}
}