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

Bug Shader objects leaking in memory with only reference "ScriptMapper" on scene unload

Discussion in 'General Graphics' started by Raul_T, Jan 11, 2023.

  1. Raul_T

    Raul_T

    Joined:
    Jan 10, 2015
    Posts:
    363
    As per title, after profiling memory usage with the memory profiler on a development build, we figured that most of our shaders of a given scene are still stuck in memory after scene change.

    They seem to only be referenced by a mysterious "ScriptMapper" on the C++/native side of things, and they are not used in any way in the scene the game switches to.

    upload_2023-1-11_12-51-25.png

    What is the ScriptMapper and how we can avoid this? From my understanding, shaders should work like the other resources that also unload on a Resources.UnloadUnused when they are no longer used, similar to textures, meshes, etc. though they are stuck referenced by this ScriptMapper thing.

    Any easy way to avoid this?
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,844
    Hi!
    May I ask you to file a bug report? This is the object that provides the "Shader.Find" functionality.
     
  3. Raul_T

    Raul_T

    Joined:
    Jan 10, 2015
    Posts:
    363
    Hi!

    Will try, I'll have to do a dummy project where this is reproductible first, as this is an NDA-ed project I'm working on as a contractor, so submitting the actual project source through the bug report is a no go for me unfortunately.

    Will get back to you with a case number when I did the report with the dummy project. Thanks

    P.S. For reference this is on 2020.3.38f1 (built-in pipeline if it matters), forgot to mention in the initial post.
    P.P.S. Also checked since the original post, it does the same whether the "keep loaded shaders alive" is ticked or not in player settings.
     
    aleksandrk likes this.
  4. Raul_T

    Raul_T

    Joined:
    Jan 10, 2015
    Posts:
    363
    Coming back to this - so in the meanwhile I had to format my workstation and did a fresh reimport of the project, and at the same time an upgrade to 2020.3.44f1 and the issue is no longer reproductible neither in the main project or dummy repro projects.

    So not sure what was it, either something wrong in the project library or something that possibly got fixed between .38 and .44, but seems to be all good for now.

    (On a side note - not low level graphics related issues, but any chance you could ping the relevant people for any of those reports? both have bug reports submitted and case numbers attached in the threads: Bug - PostProcessingStack v2 3.2.2 leaks rendertextures in memory with 0 references after scene change - Unity Forum , Bug - Terrain trees are leaking runtime created materials into memory (keeping referenced textures alive) - Unity Forum)