@@ -1001,6 +1001,7 @@ export class Task extends EventEmitter<ClineEvents> {
10011001 this . browserSession . closeBrowser ( )
10021002 this . rooIgnoreController ?. dispose ( )
10031003 this . fileContextTracker . dispose ( )
1004+ this . api ?. dispose ?.( ) // Added this line
10041005
10051006 // If we're not streaming then `abortStream` (which reverts the diff
10061007 // view changes) won't be called, so we need to revert the changes here.
@@ -1012,6 +1013,25 @@ export class Task extends EventEmitter<ClineEvents> {
10121013 await this . saveClineMessages ( )
10131014 }
10141015
1016+ // Added new dispose method as per leak report suggestion
1017+ public dispose ( ) : void {
1018+ console . log ( `[subtasks] disposing task ${ this . taskId } .${ this . instanceId } ` )
1019+ this . abortTask ( true ) // Call abortTask to ensure all resources are released
1020+
1021+ // Explicitly call dispose on the api handler again, in case abortTask didn't catch it
1022+ // or if dispose is called directly without abortTask.
1023+ this . api ?. dispose ?.( )
1024+
1025+ // Clear any other task-specific resources if they weren't handled by abortTask
1026+ if ( this . pauseInterval ) {
1027+ clearInterval ( this . pauseInterval )
1028+ this . pauseInterval = undefined
1029+ }
1030+ // Ensure other disposables are handled if not already by abortTask
1031+ // this.rooIgnoreController?.dispose(); // Already called in abortTask
1032+ // this.fileContextTracker.dispose(); // Already called in abortTask
1033+ }
1034+
10151035 // Used when a sub-task is launched and the parent task is waiting for it to
10161036 // finish.
10171037 // TBD: The 1s should be added to the settings, also should add a timeout to
0 commit comments