- Home /
memory leak when load cached texture??
In my code, I want to load some textures form WWW, and I also want it cached after first download, so I use WWW.LoadFromCacheOrDownload, then I access the texture: tex = www.assetbundle.mainAsset as Texture.
but after I don't need this tex anymore (e.g. quit current level), I find that I can't Destroy it (it is Asset from AssetBundle), so I just assign tex with null. when I load the texture again with LoadFromCacheOrDownload, a new texture copy is created. the memory usage is grown fast in profiler. I write some code to demonstrate the problem:
IEnumerator _Step()
{
//var step = new WaitForSeconds(0.1f);
var step = new WaitForEndOfFrame();
while (true)
{
//var w = new WWW("http://127.0.0.1:8080/texture.ab");
var w = WWW.LoadFromCacheOrDownload("http://127.0.0.1:8080/texture.ab", 3);
yield return w;
//w.LoadImageIntoTexture(tex2d);
tex = w.assetBundle.mainAsset as Texture;
Debug.Log(tex.name);
//Debug.Log(w.assetBundle.mainAsset);
w.assetBundle.Unload(false);
yield return step;
}
}
In the unity document, I find the api LoadImageIntoTexture, I test it, and it's fine(no extra memory grown), but I can't use LoadFromCacheOrDownload anymore, because WWWCached can only be accessed by www.assetbundle.
please help me ... thanks
Answer by ialex32x · Nov 25, 2011 at 10:12 AM
I can w.assetBundle.Unload(true) to destroy any texture loaded from this assetbundle. But the 'tex' is also invalid immediately.