I have this system that runs fine in 3.0a5 but when I upgrade it just eats up more and more memory until it crashes the computer. I’ve reduced it to the following example. The longer it runs the larger NativeArray gets in the memory profile. As far as I can tell I’m not doing anything wrong here. All the arrays are disposed of.
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
public class FillArrayFromQueueSystem : ComponentSystem
{
public struct FillArrayJob<T> : IJob where T : struct
{
internal NativeQueue<T> Queue;
internal NativeArray<T> Array;
public void Execute()
{
int index = 0;
T item;
while (Queue.TryDequeue(out item))
{
Array[index] = item;
index++;
}
}
}
protected override void OnUpdate()
{
NativeQueue<int> queue = new NativeQueue<int>(Allocator.TempJob);
for (int i = 0; i < 100000; i++)
{
queue.Enqueue(i);
}
NativeArray<int> array = new NativeArray<int>(queue.Count, Allocator.TempJob);
var fillJob = new FillArrayJob<int>
{
Queue = queue,
Array = array
}.Schedule();
fillJob.Complete();
queue.Dispose();
array.Dispose();
}
}


