mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-15 05:04:15 +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}"))
|
if (ImGui.CollapsingHeader($"#{task.Id} - {task.Status} {(subTime - task.StartTime).TotalMilliseconds}ms###task{i}"))
|
||||||
{
|
{
|
||||||
|
task.IsBeingViewed = true;
|
||||||
|
|
||||||
if (ImGui.Button("CANCEL (May not work)"))
|
if (ImGui.Button("CANCEL (May not work)"))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -1589,6 +1591,10 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
ImGui.TextUnformatted(task.Exception.ToString());
|
ImGui.TextUnformatted(task.Exception.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
task.IsBeingViewed = false;
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.PopStyleColor(1);
|
ImGui.PopStyleColor(1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ namespace Dalamud.Logging.Internal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class TaskTracker : IDisposable
|
internal class TaskTracker : IDisposable
|
||||||
{
|
{
|
||||||
|
private static readonly ModuleLog Log = new("TT");
|
||||||
private static readonly List<TaskInfo> TrackedTasksInternal = new();
|
private static readonly List<TaskInfo> TrackedTasksInternal = new();
|
||||||
private static readonly ConcurrentQueue<TaskInfo> NewlyCreatedTasks = new();
|
private static readonly ConcurrentQueue<TaskInfo> NewlyCreatedTasks = new();
|
||||||
private static bool clearRequested = false;
|
private static bool clearRequested = false;
|
||||||
|
|
@ -53,12 +54,33 @@ namespace Dalamud.Logging.Internal
|
||||||
clearRequested = false;
|
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))
|
while (NewlyCreatedTasks.TryDequeue(out var newTask))
|
||||||
{
|
{
|
||||||
TrackedTasksInternal.Add(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];
|
var taskInfo = TrackedTasksInternal[i];
|
||||||
if (taskInfo.Task == null)
|
if (taskInfo.Task == null)
|
||||||
|
|
@ -179,6 +201,11 @@ namespace Dalamud.Logging.Internal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsCompletedSuccessfully { get; set; }
|
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>
|
/// <summary>
|
||||||
/// Gets or sets the status of the task.
|
/// Gets or sets the status of the task.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue