diff --git a/Runtime/ABase/MemoryPool/MemoryPool.Core.cs b/Runtime/ABase/MemoryPool/MemoryPool.Core.cs index c9f977f..454328c 100644 --- a/Runtime/ABase/MemoryPool/MemoryPool.Core.cs +++ b/Runtime/ABase/MemoryPool/MemoryPool.Core.cs @@ -73,7 +73,7 @@ namespace AlicizaX if (item == null) return; s_ReleaseCount++; - // 防止 ClearAll 后 Release 导致负数 + if (s_CurrentInUse > 0) s_CurrentInUse--; @@ -96,7 +96,6 @@ namespace AlicizaX if (frameCount == s_LastTickFrame) return; s_LastTickFrame = frameCount; - // 更新高水位:基于实际并发使用量(在外对象数),而非单帧 Acquire 次数 if (s_PeakInUse > s_HighWaterMark) s_HighWaterMark = s_PeakInUse; @@ -109,7 +108,6 @@ namespace AlicizaX if (s_Count <= MIN_KEEP) return; - // ---- 双阶段渐进回收 ---- if (s_IdleFrames >= IDLE_THRESHOLD) { int target = Math.Max((int)(s_HighWaterMark * 1.5f), MIN_KEEP); @@ -117,7 +115,7 @@ namespace AlicizaX if (s_Count > target) { int excess = s_Count - target; - // 阶段1:温和回收 / 阶段2:激进回收 + float ratio = s_IdleFrames < IDLE_AGGRESSIVE ? 0.25f : 0.5f; int removeCount = Math.Max((int)(excess * ratio), 1); @@ -159,9 +157,7 @@ namespace AlicizaX } } - /// - /// 预热池,启动时调用避免运行时 GC。 - /// + public static void Prewarm(int count) { count = Math.Min(count, s_MaxCapacity); @@ -181,9 +177,6 @@ namespace AlicizaX } } - /// - /// 缩容:场景切换时调用,释放多余内存。 - /// public static void Shrink(int keepCount) { if (keepCount >= s_Count) return; diff --git a/Runtime/ABase/MemoryPool/MemoryPoolRegistry.cs b/Runtime/ABase/MemoryPool/MemoryPoolRegistry.cs index 1e69b0d..97568ad 100644 --- a/Runtime/ABase/MemoryPool/MemoryPoolRegistry.cs +++ b/Runtime/ABase/MemoryPool/MemoryPoolRegistry.cs @@ -4,10 +4,7 @@ using System.Runtime.CompilerServices; namespace AlicizaX { - /// - /// 内存池注册表。非泛型路径通过此表查找对应的泛型池。 - /// 注册发生在 MemoryPool<T> 静态构造器中,仅一次。 - /// + public static class MemoryPoolRegistry { internal sealed class MemoryPoolHandle @@ -63,7 +60,6 @@ namespace AlicizaX if (s_Handles.TryGetValue(type, out var handle)) return handle.Acquire(); - // 首次访问:触发 MemoryPool 静态构造器 RuntimeHelpers.RunClassConstructor( typeof(MemoryPool<>).MakeGenericType(type).TypeHandle); @@ -85,7 +81,6 @@ namespace AlicizaX return; } - // 首次访问:触发静态构造器 RuntimeHelpers.RunClassConstructor( typeof(MemoryPool<>).MakeGenericType(type).TypeHandle); @@ -138,9 +133,7 @@ namespace AlicizaX } } - /// - /// 每帧由 MemoryPoolTicker 调用,驱动所有池的自动回收。 - /// + public static void TickAll(int frameCount) { if (s_TickArrayDirty)