Unity3D Big Memory Spike when a png is downloaded through unitywebrequest

374 views Asked by At

In profiler both device and editor - base line shifted by a diff of 27mb, but image downloaded is of size 700kb and is placed into a RawImage of size 300x300 and format RGB32.

Any idea why there is such a big change in memory?

Here is the code used:

public class randomscript : MonoBehaviour
{
    public RawImage im;


    public void OnClick()
    {
        //SocialPictureCache.LoadImage("https://wallpapercave.com/wp/PPMnOZM.jpg", SocialPictureCache.PictureType.Small, callback);

        StartCoroutine(load("https://wallpapercave.com/wp/PPMnOZM.jpg"));
    }

    public IEnumerator load(string imagePath)
    {
        using (UnityWebRequest request = new UnityWebRequest(imagePath, UnityWebRequest.kHttpVerbGET))
        {
            request.downloadHandler = new DownloadHandlerTexture();

            yield return request.SendWebRequest();

            if (request.isNetworkError || request.isHttpError)
            {
                Debug.LogError("Error while trying to load image from streaming assets - " + imagePath);
                im.gameObject.SetActive(false);
            }
            else
            {
                im.texture = DownloadHandlerTexture.GetContent(request);
            }

            request.Dispose();
        }
    }
}
0

There are 0 answers