Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Memory issue with UnityWebRequest

Discussion in 'Web' started by Romano360, May 29, 2020.

  1. Romano360


    Oct 21, 2014
    I am using UnityWebRequest to get textures from StreamingAssets and each new texture is overwriting a Texture2D object, basically replacing the old texture. The issue is, that with each download of a new texture my Texture memory is growing and especially on iOS, after 8-10 downloads the page reloads, there is no error tho, but I am assuming its an memory issue.
    Each time this coroutine is called the profiler shows the textures count rising by 1 and memory rising by around 50mb.

    Here is my code:

    Code (CSharp):
    1.     IEnumerator LoadTexture(int _id)
    2.     {
    3.         using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(Application.streamingAssetsPath + "/" + _id.ToString() + ".jpeg"))
    4.         {
    5.             yield return uwr.SendWebRequest();
    7.             if (uwr.isNetworkError || uwr.isHttpError)
    8.             {
    9.                 Debug.Log(uwr.error);
    10.             }
    11.             else
    12.             {
    13.                 smothTrans.mat.SetTexture("_tex", DownloadHandlerTexture.GetContent(uwr));
    14.             }
    15.         }      
    16.     }
    Last edited: May 29, 2020
  2. Romano360


    Oct 21, 2014
    I was playing a bit with it and it seems that even if I dont assign the downloaded data to anything, simply by downloading data it fills up my memory, as if the uwr object is not overwritten but instead instantiated as a new object every time.
    I did try to run the Dispose() on the uwr object right after the usage but it doesnt release my memory.

    Is there any other way to remove the uwr data from my memory?