Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1512,9 +1512,10 @@ export function createProgram(createProgramOptions: CreateProgramOptions): Progr
*/
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 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;
createProgramOptions = undefined!; // Stop referencing this object to ensure GC collects it.
for (const option of commandLineOptionOfCustomType) {
if (hasProperty(options, option.name)) {
if (typeof options[option.name] === "string") {
Expand Down Expand Up @@ -1569,7 +1570,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
2 changes: 2 additions & 0 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,8 @@ export function createLanguageService(
projectReferences,
};
program = createProgram(options);
// Workaround for GC bug in JSC; createProgram does not keep a reference to options, so this is safe.
options.oldProgram = undefined;

// 'getOrCreateSourceFile' depends on caching but should be used past this point.
// After this point, the cache needs to be cleared to allow all collected snapshots to be released
Expand Down
Loading