增加 SmartFrame 强制收回逻辑

This commit is contained in:
2026-01-17 15:41:55 +08:00
parent e06c60968d
commit 2992306056
7 changed files with 205 additions and 48 deletions

View File

@@ -181,4 +181,34 @@ public class SmartFrame : IDisposable
}
#endregion
// 在 SmartFrame 类中添加此方法
/// <summary>
/// [哨兵专用] 强制重置帧状态
/// 用于自愈机制:当引用计数由于逻辑 Bug 永久无法归零时,由 FramePool 强行回收
/// </summary>
internal void ForceReset()
{
// 1. 强行将计数器和归还标记归零
Interlocked.Exchange(ref _refCount, 0);
Interlocked.Exchange(ref _isReturned, 1);
// 2. 清理衍生数据,防止内存堆积
ResetDerivatives();
// 3. 标记已被强制回收,便于日志追踪
IsForceRecycled = true;
}
// 记录帧被从池中取出的精确时间
public long BorrowedTick { get; private set; }
// 标记是否已被哨兵强制回收
internal bool IsForceRecycled { get; set; }
public void MarkBorrowed()
{
BorrowedTick = Environment.TickCount64;
IsForceRecycled = false;
}
}