I’m having some trouble finding the correct way to handle this, and thought I’d see if anyone on here has some insight.
Basically, I’m loading Facebook profile pictures from the internet using the WWW class, like so:
// Start downloading the image and wait.
WWW www = new WWW(imageUrl);
yield return www;
// Save texture;
if(www.textureNonReadable != null)
{
picture = www.textureNonReadable;
}
I’ve found that when I load pictures in this way, they do not seem to get garbage collected automatically. I imagine I need to “delete” the texture asset for it to be removed from memory. Problem is, there are a number of ways to do this:
GameObject.Destroy(picture);
GameObject.DestroyImmediate(picture);
Resources.UnloadAsset(picture);
picture = null;
Even trying each of those options, I’ve found using the profiler that the texture seems to only truly be removed from memory when I call “Resources.UnloadUnusedAssets( )”.
So, ultimately, for reference, what is the correct way to remove assets like this from memory and avoid a memory leak? Or should the picture be garbage collected automatically when all references are “null” as expected?