mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Prune tasks from the infinite task list
This commit is contained in:
parent
edc38bae5e
commit
5380141d76
2 changed files with 34 additions and 1 deletions
|
|
@ -1564,6 +1564,8 @@ namespace Dalamud.Interface.Internal.Windows
|
|||
|
||||
if (ImGui.CollapsingHeader($"#{task.Id} - {task.Status} {(subTime - task.StartTime).TotalMilliseconds}ms###task{i}"))
|
||||
{
|
||||
task.IsBeingViewed = true;
|
||||
|
||||
if (ImGui.Button("CANCEL (May not work)"))
|
||||
{
|
||||
try
|
||||
|
|
@ -1589,6 +1591,10 @@ namespace Dalamud.Interface.Internal.Windows
|
|||
ImGui.TextUnformatted(task.Exception.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
task.IsBeingViewed = false;
|
||||
}
|
||||
|
||||
ImGui.PopStyleColor(1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace Dalamud.Logging.Internal
|
|||
/// </summary>
|
||||
internal class TaskTracker : IDisposable
|
||||
{
|
||||
private static readonly ModuleLog Log = new("TT");
|
||||
private static readonly List<TaskInfo> TrackedTasksInternal = new();
|
||||
private static readonly ConcurrentQueue<TaskInfo> NewlyCreatedTasks = new();
|
||||
private static bool clearRequested = false;
|
||||
|
|
@ -53,12 +54,33 @@ namespace Dalamud.Logging.Internal
|
|||
clearRequested = false;
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
var pruned = 0;
|
||||
// Prune old tasks. Technically a memory "leak" that grows infinitely otherwise.
|
||||
while (i < TrackedTasksInternal.Count)
|
||||
{
|
||||
var taskInfo = TrackedTasksInternal[i];
|
||||
if (taskInfo.IsCompleted && !taskInfo.IsBeingViewed && TrackedTasksInternal.Count > 1000)
|
||||
{
|
||||
TrackedTasksInternal.RemoveAt(i);
|
||||
pruned++;
|
||||
continue;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
// if (pruned > 0)
|
||||
// Log.Debug($"Pruned {pruned} tasks");
|
||||
|
||||
// Consume from a queue to prevent iteration errors
|
||||
while (NewlyCreatedTasks.TryDequeue(out var newTask))
|
||||
{
|
||||
TrackedTasksInternal.Add(newTask);
|
||||
}
|
||||
|
||||
for (var i = 0; i < TrackedTasksInternal.Count; i++)
|
||||
// Update each task
|
||||
for (i = 0; i < TrackedTasksInternal.Count; i++)
|
||||
{
|
||||
var taskInfo = TrackedTasksInternal[i];
|
||||
if (taskInfo.Task == null)
|
||||
|
|
@ -179,6 +201,11 @@ namespace Dalamud.Logging.Internal
|
|||
/// </summary>
|
||||
public bool IsCompletedSuccessfully { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this task is being viewed.
|
||||
/// </summary>
|
||||
public bool IsBeingViewed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the status of the task.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue