So I have receiving none critical error at OnCreateManager () after NativeArray allocation.
A Native Collection has not been disposed, resulting in a memory leak C:\User\ …
None critical, as code runs.
To simplyfy
// for now
static public List <Nodes> octrees = new List <Nodes> () ;
public struct Nodes
{
public int lastNodeIndex ;
public NativeArray <Bounds> bounds ;
...
}
protected override void OnCreateManager (int capacity)
{
NodesData octree = new NodesData () ;
octree.bounds = new NativeArray<Bounds> ( 100, Allocator.Persistent ) ;
...
// for now storing in the list
octrees.Add ( octree ) ;
// If I try add dispose, it throws error (see spoiler for full description)
// InvalidOperationException: The native container has been declared as [WriteOnly] in the job, but you are reading from it.
octree.a_bounds.Dispose () ;
}
InvalidOperationException: The native container has been declared as [WriteOnly] in the job, but you are reading from it.
Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckReadAndThrowNoEarlyOut (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) <0x1c7831c0 + 0x00052> in :0
Unity.Collections.NativeArray1[T].CheckElementReadAccess (System.Int32 index) (at C:/buildslave/unity/build/Runtime/Export/NativeArray/NativeArray.cs:113) Unity.Collections.NativeArray1[T].get_Item (System.Int32 index) (at C:/buildslave/unity/build/Runtime/Export/NativeArray/NativeArray.cs:134)
ECS.Octree.Point.BoundingOctreeAddNodeSystem._Add2RootNode (System.Int32 i_octreeIndex, System.Int32 i_nodeIndex, ECS.Octree.EntityInstance entityInstance, ECS.Octree.Bounds entityBounds) (at Assets/Project/Scripts/Octree/Systems/BoundingOctreeAddNodeSystem.cs:455)
ECS.Octree.Point.BoundingOctreeAddNodeSystem._AddEntity (System.Int32 i_octreeIndex, ECS.Octree.EntityInstance entityInstance) (at Assets/Project/Scripts/Octree/Systems/BoundingOctreeAddNodeSystem.cs:418)
ECS.Octree.Point.BoundingOctreeAddNodeSystem+AddNode.Execute () (at Assets/Project/Scripts/Octree/Systems/BoundingOctreeAddNodeSystem.cs:268)
Unity.Jobs.IJobExtensions+JobStruct`1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at C:/buildslave/unity/build/Runtime/Jobs/Managed/IJob.cs:30)
Without dispose it works. However it throws errors at initialization, then let code run.
What I am missing?
[ReadOnly] ?
I would like indicate one more thing upon that error message, since it came back, after migrating to latest Entities preview 11.
It is more feature request.
It would be nice, if such error …
A Native Collection has not been disposed, resulting in a memory leak. It was allocated at C:\Users.…\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.collections@0.0.9-preview.3\Unity.Collections\NativeList.cs:24.
… could point into a script, where the error is generated. I got multiple scripts in project with native arrays and not sure, where the error is called from. Had no errors before upgrade, so now I need check manually every possible location, where dispose may be missing.
I have it on my todo list to add an option to track the callstack of these allocations. That should make them easy to track down. I should be able to get to this soon!
Most of them have some hints (# line of code) to allow track them down. Or even double click works.
But still having from to time, these which are hard to track down.
With latest Entities 0.0.12 preview 20, error shows now the system *.cs file name and the job line.
This is big help already. Thx @simonm_unity
However, error do not indicates, which NativeArray may cause the problem.
So if you have more than one array, this may become tedious to find source of issue.
How do I enable the full stack trace on 2019.2.0a4? I get a bunch of "
A Native Collection has not been disposed, resulting in a memory leak. Enable Full StackTraces to get more details." without any traces, just that line. Already tried enabling it from the console menu and player settings, even disabled burst but still the same.
That menu option comes with the Jobs package. Good luck finding the right combination of versions to make it compile. Wiping the shader and package cache does help sometimes.
if you are looking for the option and you only see Burst inside the Jobs menu, then you have to go to the package manager and install the Entities package, that has a lot of dependencies and will make the rest of the options visible (at least with 2019.4).
After that you will see the Leak Detection options and the jobs debugger.
I get [quote]
A Native Collection has not been disposed, resulting in a memory leak. Enable Full StackTraces to get more details.
[/quote] I believe this is related to PlayFab.