增加 SmartFrame 强制收回逻辑
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user