Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Discussion Memory Leak in URP PerLight2D

Discussion in '2D' started by paulg5682, May 18, 2023.

  1. paulg5682

    paulg5682

    Joined:
    Feb 14, 2016
    Posts:
    11
    I have 2 memory leaks in my application. The stack trace makes in look like it is something with the game engine. Can someone confirm that it is not a bug in my scripts? Either way, is there something I can do about it?

    LEAK 1:

    Found 1 leak(s) from callstack:
    0x00000198798ae613 (Mono JIT Code) Unity.Collections.NativeArray`1<UnityEngine.Rendering.Universal.PerLight2D>:Allocate (int,Unity.Collections.Allocator,Unity.Collections.NativeArray`1<UnityEngine.Rendering.Universal.PerLight2D>&)
    0x00000198798ae213 (Mono JIT Code) Unity.Collections.NativeArray`1<UnityEngine.Rendering.Universal.PerLight2D>:.ctor (int,Unity.Collections.Allocator,Unity.Collections.NativeArrayOptions)
    0x00000198798adeb3 (Mono JIT Code) UnityEngine.Rendering.Universal.LightBatch:.ctor () (at ./Library/PackageCache/com.unity.render-pipelines.universal@15.0.5/Runtime/2D/Passes/Utility/LightBatch.cs:29)
    0x00000198798ad8a3 (Mono JIT Code) UnityEngine.Rendering.Universal.RendererLighting:.cctor () (at ./Library/PackageCache/com.unity.render-pipelines.universal@15.0.5/Runtime/2D/Passes/Utility/RendererLighting.cs:80)
    0x000001973933f285 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)
    0x00007ffd7052de54 (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
    0x00007ffd70478584 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3066)
    0x00007ffd704738a5 (mono-2.0-bdwgc) mono_runtime_class_init_full (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:563)
    0x00007ffd7058238b (mono-2.0-bdwgc) mono_method_to_ir (at C:/build/output/Unity-Technologies/mono/mono/mini/method-to-ir.c:9932)
    0x00007ffd70523950 (mono-2.0-bdwgc) mini_method_compile (at C:/build/output/Unity-Technologies/mono/mono/mini/mini.c:3492)
    0x00007ffd705252d7 (mono-2.0-bdwgc) mono_jit_compile_method_inner (at C:/build/output/Unity-Technologies/mono/mono/mini/mini.c:4086)
    0x00007ffd7052bd1c (mono-2.0-bdwgc) mono_jit_compile_method_with_opt (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:2700)
    0x00007ffd7061eaaf (mono-2.0-bdwgc) common_call_trampoline (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-trampolines.c:641)
    0x00007ffd7061f76d (mono-2.0-bdwgc) mono_vcall_trampoline (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-trampolines.c:866)
    0x00000197aafb1596 ((<unknown>))
    0x000001987989bd28 (Mono JIT Code) UnityEngine.Rendering.Universal.ScriptableRenderer:ExecuteRenderPass (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Rendering.Universal.ScriptableRenderPass,UnityEngine.Rendering.Universal.RenderingData&) (at ./Library/PackageCache/com.unity.render-pipelines.universal@15.0.5/Runtime/ScriptableRenderer.cs:1581)
    0x000001987989ab0b (Mono JIT Code) UnityEngine.Rendering.Universal.ScriptableRenderer:ExecuteBlock (int,UnityEngine.Rendering.Universal.ScriptableRenderer/RenderBlocks&,UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Rendering.Universal.RenderingData&,bool) (at ./Library/PackageCache/com.unity.render-pipelines.universal@15.0.5/Runtime/ScriptableRenderer.cs:1537)
    0x0000019879884bd3 (Mono JIT Code) UnityEngine.Rendering.Universal.ScriptableRenderer:Execute (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Rendering.Universal.RenderingData&) (at ./Library/PackageCache/com.unity.render-pipelines.universal@15.0.5/Runtime/ScriptableRenderer.cs:1320)
    0x00000198798480bb (Mono JIT Code) UnityEngine.Rendering.Universal.UniversalRenderPipeline:RenderSingleCamera (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Rendering.Universal.CameraData&,bool) (at ./Library/PackageCache/com.unity.render-pipelines.universal@15.0.5/Runtime/UniversalRenderPipeline.cs:712)


    LEAK 2:

    Found 1 leak(s) from callstack:
    0x00000197b01cd4a3 (Mono JIT Code) Unity.Collections.NativeArray`1<int>:Allocate (int,Unity.Collections.Allocator,Unity.Collections.NativeArray`1<int>&)
    0x00000197b01cd103 (Mono JIT Code) Unity.Collections.NativeArray`1<int>:.ctor (int,Unity.Collections.Allocator,Unity.Collections.NativeArrayOptions)
    0x00000198798adfdb (Mono JIT Code) UnityEngine.Rendering.Universal.LightBatch:.ctor () (at ./Library/PackageCache/com.unity.render-pipelines.universal@15.0.5/Runtime/2D/Passes/Utility/LightBatch.cs:30)
    0x00000198798ad8a3 (Mono JIT Code) UnityEngine.Rendering.Universal.RendererLighting:.cctor () (at ./Library/PackageCache/com.unity.render-pipelines.universal@15.0.5/Runtime/2D/Passes/Utility/RendererLighting.cs:80)
    0x000001973933f285 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)
    0x00007ffd7052de54 (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
    0x00007ffd70478584 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3066)
    0x00007ffd704738a5 (mono-2.0-bdwgc) mono_runtime_class_init_full (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:563)
    0x00007ffd7058238b (mono-2.0-bdwgc) mono_method_to_ir (at C:/build/output/Unity-Technologies/mono/mono/mini/method-to-ir.c:9932)
    0x00007ffd70523950 (mono-2.0-bdwgc) mini_method_compile (at C:/build/output/Unity-Technologies/mono/mono/mini/mini.c:3492)
    0x00007ffd705252d7 (mono-2.0-bdwgc) mono_jit_compile_method_inner (at C:/build/output/Unity-Technologies/mono/mono/mini/mini.c:4086)
    0x00007ffd7052bd1c (mono-2.0-bdwgc) mono_jit_compile_method_with_opt (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:2700)
    0x00007ffd7061eaaf (mono-2.0-bdwgc) common_call_trampoline (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-trampolines.c:641)
    0x00007ffd7061f76d (mono-2.0-bdwgc) mono_vcall_trampoline (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-trampolines.c:866)
    0x00000197aafb1596 ((<unknown>))
    0x000001987989bd28 (Mono JIT Code) UnityEngine.Rendering.Universal.ScriptableRenderer:ExecuteRenderPass (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Rendering.Universal.ScriptableRenderPass,UnityEngine.Rendering.Universal.RenderingData&) (at ./Library/PackageCache/com.unity.render-pipelines.universal@15.0.5/Runtime/ScriptableRenderer.cs:1581)
    0x000001987989ab0b (Mono JIT Code) UnityEngine.Rendering.Universal.ScriptableRenderer:ExecuteBlock (int,UnityEngine.Rendering.Universal.ScriptableRenderer/RenderBlocks&,UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Rendering.Universal.RenderingData&,bool) (at ./Library/PackageCache/com.unity.render-pipelines.universal@15.0.5/Runtime/ScriptableRenderer.cs:1537)
    0x0000019879884bd3 (Mono JIT Code) UnityEngine.Rendering.Universal.ScriptableRenderer:Execute (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Rendering.Universal.RenderingData&) (at ./Library/PackageCache/com.unity.render-pipelines.universal@15.0.5/Runtime/ScriptableRenderer.cs:1320)
    0x00000198798480bb (Mono JIT Code) UnityEngine.Rendering.Universal.UniversalRenderPipeline:RenderSingleCamera (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Rendering.Universal.CameraData&,bool) (at ./Library/PackageCache/com.unity.render-pipelines.universal@15.0.5/Runtime/UniversalRenderPipeline.cs:712)
     
  2. johnetc

    johnetc

    Joined:
    Oct 15, 2012
    Posts:
    6
    Same here. I've reported a bug from editor
     
  3. johnetc

    johnetc

    Joined:
    Oct 15, 2012
    Posts:
    6
    Looks like it could be related to this line in LayoutDataStore(?) as I'm hitting this breakpoint when connected to Rider debugger

    Code (CSharp):
    1. public unsafe byte* GetComponentDataPtr(int index) => this.m_Chunks[index / this.ComponentCountPerChunk].Buffer + index % this.ComponentCountPerChunk * this.Size;
     
  4. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    96
    Hi @paulg5682, the fix for these leaks has landed in Unity 2023.1.0b19.