Loading 4096 texture causes huge mono heap grow, with 2048 almost no offect on mono heap

Hi, i have noticed that loading huge custom file that represent compressed texture using UnityWebRequest and creating texture in runtime with it’s byte data (using LoadRawTextureData) creates huge mono heap grow that cannot be released. here is the sample code:

using (var downloadRequest = UnityWebRequest.Get(mainUrl))
            {
                byte[] bytes= null;
                yield return downloadRequest.SendWebRequest();
               
                bytes= new byte[(int)downloadRequest.downloadedBytes - header];
                Buffer.BlockCopy(downloadRequest.downloadHandler.data, header, bytes, 0, (int)downloadRequest.downloadedBytes - header);
               
                texture.LoadRawTextureData(bytes);
                texture.Apply(false, true);
                texture.wrapMode = TextureWrapMode.Clamp;
               
            }

any ideas?

pearhaps the optional parameter (true) with GetTexture

string url = "http://www.my-server.com/myimage.png";
using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url, true))
1 Like

why loading as bytes and not using the UnityWebRequestTexture?
and as sumpfkraut wrote, set nonReadable as true.

The wasm memory size is limited.
while some browsers on some platforms can contain large enough memory size for 20482048 image, 40964096 is too big.

The UnityWebRequestTexture know how to handle the texture on the JavaScript side, and if you set it as nonReadable, it won’t load the byte data to the wasm memory.