You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C#中IsValid()方法执行时长随运行时间递增问题排查求助

内存泄漏排查异常:IsValid()方法执行时长持续增加

我正在排查程序中的内存泄漏问题,目前已计时的所有方法执行时长均符合预期且保持稳定,唯有IsValid()方法例外。随着程序持续运行,该方法的执行时长逐渐增加,大约每30秒增加1ms。我使用StopWatch来计时该函数的执行,当前仅遍历1个始终返回true的对象。GetBestGoal()方法每秒被调用60次,为简化测试,goals列表中仅包含一个对象。

相关代码

调用IsValid()的循环代码

for (int i = 0; i < goals.Count; i++)
{
    planStopwatch.Start();
    isvalid = goals[i].IsValid(blackBoard, worldState);
    planStopwatch.Stop();
    Console.WriteLine($"Time: {planStopwatch.ElapsedMilliseconds} ms");

    if (isvalid)
    {
        int goalPriority = goals[i].Priority(blackBoard, worldState);

        if (goalPriority > hightPriority)
        {
            best = goals[i];
            hightPriority = goalPriority;
        }
    }
}

IsValid()方法实现

public override bool IsValid(BlackBoard blackBoard, WorldState worldState)
{
    return true;
}

我已对程序中所有其他方法进行基准测试,只有IsValid()方法的执行时长不稳定。


内容的提问来源于stack exchange,提问作者Terrence

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 07:12:02