From 15e442a0c8e059922824fe123d07ed236a171927 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Tue, 23 Jun 2026 10:32:20 -0400 Subject: [PATCH] perf(@angular/build): dispose builder result context early in non-watch mode Evaluates and extracts final output results into a list before calling result.dispose() in non-watch mode. This ensures all compiler worker processes (retaining the TypeScript program structures and cache) are terminated and reclaimed before yielding results to the caller for disk writing. --- .../build/src/builders/application/build-action.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/angular/build/src/builders/application/build-action.ts b/packages/angular/build/src/builders/application/build-action.ts index 77d1f16cbd2a..d7dbdc8cfe21 100644 --- a/packages/angular/build/src/builders/application/build-action.ts +++ b/packages/angular/build/src/builders/application/build-action.ts @@ -148,7 +148,13 @@ export async function* runEsBuildBuildAction( // Output the first build results after setting up the watcher to ensure that any code executed // higher in the iterator call stack will trigger the watcher. This is particularly relevant for // unit tests which execute the builder and modify the file system programmatically. - yield* emitOutputResults(result, outputOptions); + const outputResults = [...emitOutputResults(result, outputOptions)]; + if (!watch) { + await result.dispose(); + // Set to true to prevent double-disposal of the result context in the finally block on generator exit + watchLoopStarted = true; + } + yield* outputResults; // Finish if watch mode is not enabled if (!watcher) {