From e799a9e29e780dd3aee491d853a4a4a1030ecdce Mon Sep 17 00:00:00 2001 From: bbbirder <502100554@qq.com> Date: Sat, 25 May 2024 03:05:15 +0800 Subject: [PATCH] opt: avoid memory peak on chunk rent (cherry picked from commit 4e6e2c5318a56ebcd6dd7fa5768beb3aa9000e6f) --- src/Arch/Core/Archetype.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Arch/Core/Archetype.cs b/src/Arch/Core/Archetype.cs index 82ea7b5..d7036ba 100644 --- a/src/Arch/Core/Archetype.cs +++ b/src/Arch/Core/Archetype.cs @@ -547,6 +547,11 @@ public int CalculateEntitiesPerChunk(ComponentType[] types) [MethodImpl(MethodImplOptions.AggressiveInlining)] private void EnsureChunkCapacity(int newCapacity) { + if (ChunkCapacity >= newCapacity) + { + return; + } + // Increase chunk array size var newChunks = ArrayPool.Shared.Rent(newCapacity); Array.Copy(Chunks, newChunks, ChunkCapacity);