lundi 19 janvier 2015

Unity LoadImageIntoTexture memory leak

I am building something that requires users to load images from an external folder, display them and sort them into different folders individually.


My problem is that each time I load in a new image the memory usage goes up but never comes back down. This happens when i run it as an .exe or in editor. When I run it in editor the memory usage doesn't go down even when I stop running it, I have to manually exit the unity editor and restart it. If I go back to an image I've seen the memory doesn't increase, so I know that it's keeping these images in memory and I don't know how to remove them.


I have checked all the resources I can find about this online and have followed and changed as much as I can but my problem is still happening. Any help would be great.


I added the code that loads and sets the texture as the main texture below. the memory leak does not happen when I comment out the LoadImageIntoTexture line.



IEnumerator LoadImage(string userFolder)
{
WWW newFile = new WWW("file://"+ userFolder + pictures[current]);
yield return newFile;
Destroy(editTex);
editTex = new Texture2D(1920, 1080, TextureFormat.DXT1, false);
newFile.LoadImageIntoTexture(editTex);
newFile.Dispose();
newFile = null;
Resources.UnloadUnusedAssets();
System.GC.Collect();
}




Aucun commentaire:

Enregistrer un commentaire