static void ReleaseChunk(Chunk *chunk,
                                 EntityComponentStore *entityComponentStore,
                                 ManagedComponentStore managedComponentStore,
                                 EntityGroupManager entityGroupManager)
        {
            // Remove references to shared components
            if (chunk->Archetype->NumSharedComponents > 0)
            {
                var sharedComponentValueArray = chunk->SharedComponentValues;

                for (var i = 0; i < chunk->Archetype->NumSharedComponents; ++i)
                {
                    managedComponentStore.RemoveReference(sharedComponentValueArray[i]);
                }
            }

            if (chunk->ManagedArrayIndex != -1)
            {
                managedComponentStore.DeallocateManagedArrayStorage(chunk->ManagedArrayIndex);
                chunk->ManagedArrayIndex = -1;
            }

            if (chunk->metaChunkEntity != Entity.Null)
            {
                DestroyMetaChunkEntity(chunk->metaChunkEntity,
                                       entityComponentStore, managedComponentStore, entityGroupManager);
            }

            // this chunk is going away, so it shouldn't be in the empty slot list.
            if (chunk->Count < chunk->Capacity)
            {
                chunk->Archetype->EmptySlotTrackingRemoveChunk(chunk);
            }

            chunk->Archetype->RemoveFromChunkList(chunk);
            chunk->Archetype = null;

            entityComponentStore->FreeChunk(chunk);
        }