#Where is the memory leak?

1 messages · Page 1 of 1 (latest)

winter ivy
#

I'm getting warned of a memory leak, but when I enable stack trace for memory leak detection it stops warning me. Is there a leak here? The warning is about pointsArray, so I've only included code about said NativeArray, although I will say keyPoints uses Allocator.Temp and NativeArrayOptions.UninitializedMemory. This is in a static method with the BurstCompile attribute.

NativeArray<NativeSlice<int2>> pointsArray = new(phase + 2, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

int j = 0;
for (int i = 0; i < keyPoints.Length; i += 2, j++)
{
  pointsArray[j] = new NativeSlice<int2>(keyPoints, i, 2);
}

string debugString = $"pointsArray:";
for (int i = 0; i < pointsArray.Length; i++)
{
  debugString += $"\npointsArray[{i}]:";
  foreach (int2 p in pointsArray[i])
  {
    debugString += $" {p}";
  }
}

keyPoints.Dispose();
pointsArray.Dispose();
fleet harness
#

I've never used NativeSlice yet - but wondering if you need to dispose of the array elements before disposing of the array itself.

azure vessel
#

NativeSlice never owns a memory. Dispose is noop for it.