How to dispose NativeArray with ForEach lambda?

I’m getting “Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak”. I thought adding the .WithDisposeOnCompletion(…) was enough. Anyone else ran into this issue yet?

NativeArray<D_Occupancy> otherOccupants = GetEntityQuery(ComponentType.ReadOnly<D_Occupancy>()).ToComponentDataArray<D_Occupancy>(Allocator.TempJob);
            Entities
                .WithReadOnly(otherOccupants)
                .ForEach((Entity thisEntity, DynamicBuffer<B_Proximity> myProximityBuffer, in D_Occupancy myOccupantData) =>
            {
                myProximityBuffer.Clear();
                int i = 0;
                while (i < otherOccupants.Length)
                {
                    if (!(otherOccupants[i].entityId == thisEntity))
                    {
                        if (otherOccupants[i].QuadrantKey == myOccupantData.QuadrantKey)
                        {
                            myProximityBuffer.Add(otherOccupants[i].entityId);
                        }
                    }
                    i++;
                }
            })
            .WithDisposeOnCompletion(otherOccupants)
            .Schedule();

After scheduling, try calling:otherOccupants.Dispose(this.Dependency);

I still get the same warning. Shouldn’t the .WithDisposeOnCompletion(otherOccupants) perform the allocation clearing?

It should but I’m not sure. We don’t use Entities.ForEach() often. We use job structs. We call Dispose(JobHandle) after scheduling.

Interesting development. I removed “.WithDisposeOnCompletion()” and “otherOccupants.Dispose(this.Dependency)”.

So far I haven’t gotten the warning so feeling optimistic. I’ll update this post if I do get the warning though. THANK YOU !!