perf(context)!: release retired fibers and bound diagnostic history
This commit is contained in:
@@ -14,6 +14,7 @@ namespace ShrinkContext
|
||||
public sealed class ShrinkCtx
|
||||
{
|
||||
private readonly List<ShrinkEffectHandle> _effects = new();
|
||||
private bool _disposing;
|
||||
private readonly Dictionary<string, string>? _isolateOverlay;
|
||||
private Dictionary<string, IReadOnlyDictionary<string, object?>>? _interceptOverlay;
|
||||
|
||||
@@ -81,6 +82,13 @@ namespace ShrinkContext
|
||||
|
||||
internal void Attach(ShrinkEffectHandle handle) => _effects.Add(handle);
|
||||
|
||||
internal void Detach(ShrinkEffectHandle handle)
|
||||
{
|
||||
// During parent teardown the reverse traversal owns removal.
|
||||
if (!_disposing)
|
||||
_effects.Remove(handle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 前向已在外部执行完毕的效应:仅登记逆操作(供桥接适配器把既有 API 的"注册/注销"对包装为可逆效应)。
|
||||
/// </summary>
|
||||
@@ -98,9 +106,14 @@ namespace ShrinkContext
|
||||
/// <summary>按 LIFO 顺序执行本上下文注册的全部逆操作。</summary>
|
||||
public async UniTask DisposeAsync()
|
||||
{
|
||||
for (var i = _effects.Count - 1; i >= 0; i--)
|
||||
await _effects[i].DisposeAsync();
|
||||
_effects.Clear();
|
||||
_disposing = true;
|
||||
try
|
||||
{
|
||||
for (var i = _effects.Count - 1; i >= 0; i--)
|
||||
await _effects[i].DisposeAsync();
|
||||
_effects.Clear();
|
||||
}
|
||||
finally { _disposing = false; }
|
||||
}
|
||||
|
||||
// ---------------- 余效应(论文 3.2 / 算法 2) ----------------
|
||||
|
||||
Reference in New Issue
Block a user