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 Native Collection have not been disposed on game close

Discussion in 'Unity Analytics' started by Morphus74, Oct 10, 2022.

  1. Morphus74

    Morphus74

    Joined:
    Jun 12, 2018
    Posts:
    174
    When closing game, once in a while I get

    A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
    Code (CSharp):
    1.  
    2. Unity.Collections.NativeArray`1:.ctor(Byte[], Allocator)
    3. UnityEngine.Networking.UploadHandlerRaw:.ctor(Byte[])
    4. Unity.Services.Analytics.Internal.WebRequestHelper:CreateWebRequest(String, String, Byte[]) (at Library\PackageCache\com.unity.services.analytics@4.0.1\Runtime\Runtime\WebRequestHelper.cs:32)
    5. Unity.Services.Analytics.Internal.<FlushBufferToService>d__13:MoveNext() (at Library\PackageCache\com.unity.services.analytics@4.0.1\Runtime\Runtime\Dispatcher.cs:79)
    6. System.Runtime.CompilerServices.MoveNextRunner:InvokeMoveNext(Object)
    7. System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
    8. System.Threading.ExecutionContext:Run(ExecutionContext, ContextCallback, Object, Boolean)
    9. System.Runtime.CompilerServices.MoveNextRunner:Run()
    10. System.Threading.Tasks.<>c:<.cctor>b__7_0(Object)
    11. UnityEngine.WorkRequest:Invoke()
    12. UnityEngine.UnitySynchronizationContext:Exec()
    13. UnityEngine.UnitySynchronizationContext:ExecuteTasks()
    14.  
    15.  
    You are probably not closing your WebRequest properly, can you please validate?

    Thank
     
  2. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    189
    Hey @Morphus74

    Could you provide me with the steps to reproduce this error.
     
  3. Morphus74

    Morphus74

    Joined:
    Jun 12, 2018
    Posts:
    174
    I just have IAP/Analytics install, doing no specific transaction and just hitting stop in the editor
     
  4. damelin

    damelin

    Joined:
    Jul 3, 2012
    Posts:
    64
    I have just seen this error too (with Analytics package 4.2.0), upon hitting Stop in the Editor.

    Code (CSharp):
    1. A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
    2. Unity.Collections.NativeArray`1:.ctor(Byte[], Allocator) (at /Users/bokken/build/output/unity/unity/Runtime/Export/NativeArray/NativeArray.cs:69)
    3. UnityEngine.Networking.UploadHandlerRaw:.ctor(Byte[]) (at /Users/bokken/build/output/unity/unity/Modules/UnityWebRequest/Public/UploadHandler/UploadHandler.bindings.cs:95)
    4. Unity.Services.Analytics.Internal.WebRequestHelper:CreateWebRequest(String, String, Byte[]) (at Library/PackageCache/com.unity.services.analytics@4.2.0/Runtime/Runtime/WebRequestHelper.cs:32)
    5. Unity.Services.Analytics.Internal.<FlushBufferToService>d__13:MoveNext() (at Library/PackageCache/com.unity.services.analytics@4.2.0/Runtime/Runtime/Dispatcher.cs:87)
    6. System.Runtime.CompilerServices.MoveNextRunner:InvokeMoveNext(Object)
    7. System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
    8. System.Threading.ExecutionContext:Run(ExecutionContext, ContextCallback, Object, Boolean)
    9. System.Runtime.CompilerServices.MoveNextRunner:Run()
    10. System.Threading.Tasks.<>c:<.cctor>b__7_0(Object)
    11. UnityEngine.WorkRequest:Invoke() (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/UnitySynchronizationContext.cs:153)
    12. UnityEngine.UnitySynchronizationContext:Exec() (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/UnitySynchronizationContext.cs:83)
    13. UnityEngine.UnitySynchronizationContext:ExecuteTasks() (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/UnitySynchronizationContext.cs:107)
    But this might be related to WebRequest's Dispose not working properly?

    Others are having issue too:
    https://forum.unity.com/threads/a-n...-disposed-resulting-in-a-memory-leak.1136068/

    Also, I have this error coming from the Playfab SDK even if they are calling Dispose on the UnityWebRequest