After few days of investigation, finally I found one of the reason that may cause the downloaded texture can’t be destroyed.
NEVER assign the WWW.texture more than once…
even like this…
if ([url]www.texture.height[/url] > 16) { /*...*/ }
Is it interesting ? Should I submit that to bug report ??
as see on the following test code, passing the www.texture to a local variable will save the life ![]()
var texture:Array = new Array();
var frame:int = 0;
var busy:int = 0;
var calls:int = 0;
var g:GameObject;
function Start ()
{
g = new GameObject.CreatePrimitive(PrimitiveType.Plane);
}
function Update()
{
if (busy < 8) { loader(); }
}
function loader()
{
busy++;
var www = new WWW("http://homepage.mac.com/antonioh/dev/loading_jpg/"+frame+".jpg");
yield www;
var _temp:Texture2D = [url]www.texture;[/url]
texture.Push(_temp);
var r:int = parseInt(Random.Range(0, texture.length-1));
if(texture.length > 256)
{
Destroy(texture[r]);
texture.RemoveAt(r);
}
//if([url]www.texture.height[/url] > 16) { /* BEWARE! memory overflow ahead :p*/ }
if(_temp.height > 16) { /* the texture's memory return to OS :) */ }
g.renderer.material.mainTexture = _temp;
www.Dispose();
www = null;
frame = (frame+1)%1024;
busy--;
calls++;
}
function OnGUI()
{
str=GUI.TextField(Rect(12,12,200,24),"length: "+texture.length+" calls: "+calls);
}
Hope the above information is helpful for someone like to download thousands of texture very often ![]()
Have a nice weekend to all,
Antonio Hui