Skip to content

Commit

Permalink
Ensure createProgram stops referencing rootNamesOrOptions to ensure o…
Browse files Browse the repository at this point in the history
…ldProgram is GC'd (#61034)

Co-authored-by: cplepage <[email protected]>
  • Loading branch information
jakebailey and cplepage authored Jan 23, 2025
1 parent 5e52b28 commit 51d9a98
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1511,10 +1511,14 @@ export function createProgram(createProgramOptions: CreateProgramOptions): Progr
* @returns A 'Program' object.
*/
export function createProgram(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[]): Program;
export function createProgram(rootNamesOrOptions: readonly string[] | CreateProgramOptions, _options?: CompilerOptions, _host?: CompilerHost, _oldProgram?: Program, _configFileParsingDiagnostics?: readonly Diagnostic[]): Program {
const createProgramOptions = isArray(rootNamesOrOptions) ? createCreateProgramOptions(rootNamesOrOptions, _options!, _host, _oldProgram, _configFileParsingDiagnostics) : rootNamesOrOptions; // TODO: GH#18217
const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion } = createProgramOptions;
let { oldProgram } = createProgramOptions;
export function createProgram(_rootNamesOrOptions: readonly string[] | CreateProgramOptions, _options?: CompilerOptions, _host?: CompilerHost, _oldProgram?: Program, _configFileParsingDiagnostics?: readonly Diagnostic[]): Program {
let _createProgramOptions = isArray(_rootNamesOrOptions) ? createCreateProgramOptions(_rootNamesOrOptions, _options!, _host, _oldProgram, _configFileParsingDiagnostics) : _rootNamesOrOptions; // TODO: GH#18217
const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion, host: createProgramOptionsHost } = _createProgramOptions;
let { oldProgram } = _createProgramOptions;
// Stop referencing these objects to ensure GC collects them.
_createProgramOptions = undefined!;
_rootNamesOrOptions = undefined!;

for (const option of commandLineOptionOfCustomType) {
if (hasProperty(options, option.name)) {
if (typeof options[option.name] === "string") {
Expand Down Expand Up @@ -1569,7 +1573,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
tracing?.push(tracing.Phase.Program, "createProgram", { configFilePath: options.configFilePath, rootDir: options.rootDir }, /*separateBeginAndEnd*/ true);
performance.mark("beforeProgram");

const host = createProgramOptions.host || createCompilerHost(options);
const host = createProgramOptionsHost || createCompilerHost(options);
const configParsingHost = parseConfigHostFromCompilerHostLike(host);

let skipDefaultLib = options.noLib;
Expand Down

0 comments on commit 51d9a98

Please sign in to comment.