protected override void OnDestroyManager() { EndExclusiveEntityTransaction(); ComponentJobSafetyManager.PreDisposeCheck(); // Clean up all entities. This is needed to free all internal buffer allocations so memory is not leaked. using (var allEntities = GetAllEntities()) { DestroyEntity(allEntities); } ComponentJobSafetyManager.Dispose(); ComponentJobSafetyManager = null; Entities->OnDestroy(); UnsafeUtility.Free(Entities, Allocator.Persistent); Entities = null; ArchetypeManager.Dispose(); ArchetypeManager = null; m_GroupManager.Dispose(); m_GroupManager = null; m_ExclusiveEntityTransaction.OnDestroyManager(); m_SharedComponentManager.Dispose(); UnsafeUtility.Free(m_CachedComponentTypeArray, Allocator.Persistent); m_CachedComponentTypeArray = null; UnsafeUtility.Free(m_CachedComponentTypeInArchetypeArray, Allocator.Persistent); m_CachedComponentTypeInArchetypeArray = null; }