Efficient ways to optimize the downloading and unloading of large textures?
Hi guys I am working on a project that downloads lots of textures, many of them for a cube map, places them , and then once the player changes their options we unload and the textures and begin loading our new set of images . I wanted to know is their a more efficient way that I can be doing this I have recently begun to encounter some memory issues on both android and iOS machines .
Here is an example of unloading one group of our images :
public void UnloadTextures(){
Resources.UnloadAsset(leftPano);
Resources.UnloadAsset(rightPano);
}
private void UnloadTextures(Renderer pano){
Material[] mats = pano.materials;
for(int i = 0; i < mats.Length; i++) {
Texture2D tempTex = mats [i].mainTexture as Texture2D;
DestroyImmediate (tempTex,true);
}
Resources.UnloadUnusedAssets();
}
Here is a second example of unloading our texture in the project :
Texture2D leftTemp = leftShutter.texture as Texture2D;
Texture2D rightTemp = rightShutter.texture as Texture2D;
leftImage.texture = (Texture)PortalCache.LoadImageFromCache(downloader.DownloadedImageLibrary.leftSpinPaths[index]) as Texture;
leftShutter.SetNativeSize();
rightImage.texture = (Texture)PortalCache.LoadImageFromCache(downloader.DownloadedImageLibrary.rightSpinPaths[index]) as Texture;
rightShutter.SetNativeSize();
Resources.UnloadAsset(leftTemp);
Resources.UnloadAsset(rightTemp);
Is there anything I can be doing that is more efficient in terms of unloading these textures? As I mentioned I am also downloading them from web , So perhaps there is an efficient way to manage downloading of textures from the web ?
i know thats accessing materials creates copies of them. use shared$$anonymous$$aterials ins$$anonymous$$d. what I don't know, if the fact that the original materials still hold the textures due to the copy, if the textures can or cannot be unloaded.
I'd use the profiler and check on which calls memory goes up and when it's not going down.
Thank you ! that gives me a good place to start looking !
Answer by divyajalan · Aug 20, 2019 at 10:13 AM
Did you figure out anything? Even I have a similar usecase where I'm downloading huge textures. Need to know how to free up the memory efficiently
Your answer
Follow this Question
Related Questions
What is the correct way to store circular references in Unity? 1 Answer
Memory error pls help 0 Answers
Unity Total System Memory Usage GO CRAZY?! memory leak 0 Answers
IOS unity taking lot of memory 0 Answers