Search Unity

Can't dispose NativeList [Solved]

Discussion in 'Scripting' started by MrDumle, Aug 29, 2021.

  1. MrDumle

    MrDumle

    Joined:
    Apr 16, 2014
    Posts:
    6
    I've seen some threads about this issue but none helps me.
    When I quit the player I get this message.

    A Native Collection has not been disposed, resulting in a memory leak. Enable Full StackTraces to get more details.


    What am I doing wrong here. I feel like I'm missing something fundamental how these NativeList works.
    This is the code:

    Code (CSharp):
    1. public class Testo : MonoBehaviour
    2. {
    3.     NativeList<float3> output_verts;
    4.  
    5.     void Start()
    6.     {      
    7.         var output_verts = new NativeList<float3>(Allocator.Persistent);
    8.  
    9.     }
    10.     public void OnDestroy() {
    11.         if(output_verts.IsCreated){ output_verts.Dispose();
    12.  }
    13.  
    14.     }
     
  2. giollord

    giollord

    Joined:
    Mar 23, 2017
    Posts:
    17
    If you put some log to beginning of OnDestroy, error will be after that log or before?
     
  3. MrDumle

    MrDumle

    Joined:
    Apr 16, 2014
    Posts:
    6
    Nevermind. The "var" was the issue. I wanna shoot myself.
     
    Bunny83 likes this.