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. Dismiss Notice

Texture memory usage doubles the next frame

Discussion in 'General Graphics' started by blossomgames, Apr 2, 2019.

  1. blossomgames

    blossomgames

    Joined:
    Oct 23, 2013
    Posts:
    30
    I use this to measure how much of memory a texture occupies:
    Code (csharp):
    1.  
    2. Profiler.GetRuntimeMemorySize(cachedTexture)
    3.  
    I create a texture like this:
    Code (csharp):
    1.  
    2. cachedTexture = new Texture2D(2, 2);
    3. cachedTexture.LoadImage(contentData);
    4.  
    So pretty simple. Then I print in Update method the memory usage. Right after LoadImage my texture is 18 MBs in memory. But in the next frame, in Update method, it is around 40 MBs. And that is the number the profiler measures. Where does that come from?
     
  2. Sh-Shahrabi

    Sh-Shahrabi

    Joined:
    Sep 28, 2018
    Posts:
    56
    try cachedTexture.mipmapCount and see if there is a mip chain. It can be that the extra 30 mb are the mip chain.
     
  3. blossomgames

    blossomgames

    Joined:
    Oct 23, 2013
    Posts:
    30
    That would be weird. A texture that weighs x MBs without mipmaps, weights 4/3*x with mipmaps. So the numbers don't really add up.
     
  4. blossomgames

    blossomgames

    Joined:
    Oct 23, 2013
    Posts:
    30
    Another interesting observation. I used Compress method to compress the texture. And now GetRuntimeMemorySize returns 30 MBs all the time, but when I take a memory snapshot in the profiler I can clearly see that this particular texture weighs 3 MBs in memory (to be more precise: 3 MBs when found in the Inspector window, but 30 MBs in the profiler's snapshot textures list). That's a huge difference.