I have been trying to trace down a memory leak in my program and every method I have timed thus far has been as predicted and constant except for this one. As I leave the program running the time to execute the IsValid() method takes progressively longer as the program runs, gaining 1ms every 30 seconds or so. I am using StopWatch to time the execution of the function and I am only iterating on 1 object that always return true. The GetBestGoal() method is being called 60 times per second and there is only one object in the list of goals for simplicity.
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;
}
}
}
public override int Priority(BlackBoard blackBoard, WorldState worldState)
{
return 0;
}
I have tried benchmarking all other methods in the program and IsValid() is the only one that doesn’t have a constant execution time.
code
Terrence is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.