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

Question Cascade Shadow Map atlas and post process stuff causing memory leak?

Discussion in 'High Definition Render Pipeline' started by SNicolas, Aug 11, 2020.

  1. SNicolas

    SNicolas

    Joined:
    Apr 6, 2013
    Posts:
    32
    Hi there,

    I noticed some Render Textures not being freed when leaving the game scene to, for example, a simple main screen. One of them has to do with the shadow atlas cascade and others about post-processing stuff.

    I use Unity 2019.4.6 and HDRP 7.4.1.

    Please see image attached from memory profiler. Diff was made using main screen captured before and after game screen. I sorted the "New" group by bigger size.

    Any help is more than welcome. Thank you.

    Sergi

    upload_2020-8-11_13-59-31.png
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,130
    That's expected behavior unless you are calling Resources.UnloadUnusedAssets after the previous scene has been unloaded or you loaded an empty scene in between. Assets used in a scene are kept in memory as the scene is unloaded until the next scene after is unloaded, just in case the scene you load after you unload the first one shares the needs for some resources and Unity would otherwise spend too much time needlessly loading and unloading them.

    They have a ref count of 0 so they will be unloaded the next time UnloadUnusedAssets triggers, either because you call it or because a scene is unloaded.
     
  3. SNicolas

    SNicolas

    Joined:
    Apr 6, 2013
    Posts:
    32
    Hi Martin,

    Thank you for your answer.

    Yeah, I realized that after a few more captures those references were gone but my memory (task manager) keeps accumulating large chunks of mb (20-30) each time I go from game scene to main menu.

    There is a loading screen in between that I unload, as the next scene is loaded async, but I can't find where the issue comes from. Is is possible to send a log/capture or something from the memory profiler so you maybe could take a quick look? That would help a lot to point out the issue.

    Thanks again,

    Sergi
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,130
    The two scene unloads needed to be non-async (or passing an optional book to unload assets) to trigger Resources.UnloadUnusedAssets. you could also just call it your self in that loading scene to be sure.

    You might want to look into the MemoryMap in diff view to find what's different. Maybe it isn't object related but due to Memory pools or heaps expanding?

    Not usually no, unless it's a bug with the Engine, then as a bug report. Also I'm technically on vacation right now ;)
     
  5. SNicolas

    SNicolas

    Joined:
    Apr 6, 2013
    Posts:
    32
    Thank you Martin. I will take a look. :) Enjoy your Holidays!

    Sergi
     
    MartinTilo likes this.