You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add clear_task_if_completed function to WorkerThreadPools
Adds clear_task_if_completed function to worker threadpools
Currently every task must be waited on (wait_for_task_completion) for their resources to be removed from memory (#84888). This is addressed in the docs however said solution may not always be intuitive or ideal as the function known as "wait_for_task_completion" is used even in cases where no waiting is necessary as it does the double duty of waiting, and also clearing memory.
While it makes sense that if you wait for a task, and it finishes, it should be cleared from memory, it is not always intuitive that you HAVE to wait for a task that you know is completed (via is_task_completed) to prevent a memory leak.
This can currently be circumvented by using an if statement (if is_task_completed: wait_for_task_completion) however said usage is ugly and also unintuitive.
This commit adds a function which checks if the task is completed, and then returns true and clears resources if so. Essentially doing the same job as wait_for_task_completion if already completed, HOWEVER not binding the main thread (or the thread it is called from) in the case the task isn't.
This allows for resource clearing without accidentally pausing the entire thread if not completed, in the case of a non essential functions such as saving (which can be allowed to operate in the background without pausing the entire game/main thread)
Copy file name to clipboardexpand all lines: doc/classes/WorkerThreadPool.xml
+8
Original file line number
Diff line number
Diff line change
@@ -72,6 +72,14 @@
72
72
[b]Warning:[/b] Every task must be waited for completion using [method wait_for_task_completion] or [method wait_for_group_task_completion] at some point so that any allocated resources inside the task can be cleaned up.
73
73
</description>
74
74
</method>
75
+
<methodname="clear_task_if_completed">
76
+
<returntype="bool" />
77
+
<paramindex="0"name="task_id"type="int" />
78
+
<description>
79
+
Returns [code]true[/code] if the task with the given ID is completed, and then removes it from memory (if completed).
80
+
[b]Note:[/b] You should only call this method between adding the task and awaiting its completion.
0 commit comments