Half-gigabyte allocations in ArchetypeChunkIterator ctor

Been trying to get to the bottom of a memory-leak type issue for a while. I can’t find anything specific in my game code that is leaking, nor does the DOTS leak detection, but the total used memory ratchets up around every 5 seconds by quarter/half gigabyte increments. The exact call stack seems pretty random; it seems to always happen in systems that use the Entities.ForEach().Run() builder and almost always includes the ArchetypeChunkIterator ctor invoking a block allocation from the RewindableAllocator. I haven’t been able to make a minimal repro yet. Using Unity 2020.3 and ECS 0.51

Any advice for diagnosing this? The memory profiler doesn’t seem to have good insight into native allocations.

I was able to create a minimal repro of this in Unity 2020.3, Entities 0.51, and IL2CPP.

using Unity.Entities;

public class Bootstrap : ICustomBootstrap
{
    public bool Initialize(string name)
    {
        var world = World.DefaultGameObjectInjectionWorld = new World(name);

        DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, new [] { typeof(TestSystem) });
        ScriptBehaviourUpdateOrder.AppendWorldToCurrentPlayerLoop(world);

        return true;
    }
}

public partial class TestSystem : SystemBase
{
    protected override void OnCreate()
    {
        EntityManager.CreateEntity(typeof(TestBufferComponent));
    }

    protected override void OnUpdate()
    {
        Entities.ForEach((ref DynamicBuffer<TestBufferComponent> buffer) => {}).Run(); // comment out to fix leak
    }
}

public struct TestBufferComponent : IBufferElementData { }

Running this in an empty project and scene will show the Total Used Memory in the profiler ratchet up by gigabytes at a time. The leak is frame rate dependent; running this as a Windows build with vsync turned off loops at 1000 FPS and the reported Total Used Memory reaches 32gb in less than a minute. This is looking like a bug in the profiling tools to me because without the profiler attached the system reports a steady 200mb memory used by the build.