Skip to content

Commit

Permalink
Replace Map with WeakMap to avoid memory leak (#4517)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceciliaavila committed Aug 8, 2023
1 parent 85a22f3 commit 5b58d10
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions libraries/adaptive-expressions/src/parser/expressionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class ExpressionParser implements ExpressionParserInterface {
*/
readonly EvaluatorLookup: EvaluatorLookup;

private static expressionDict: Map<string, ParseTree> = new Map<string, ParseTree>();
private static expressionDict: WeakMap<any, ParseTree> = new WeakMap<any, ParseTree>();

private readonly ExpressionTransformer = class
extends AbstractParseTreeVisitor<Expression>
Expand Down Expand Up @@ -279,8 +279,8 @@ export class ExpressionParser implements ExpressionParserInterface {
* @returns A ParseTree.
*/
protected static antlrParse(expression: string): ParseTree {
if (ExpressionParser.expressionDict.has(expression)) {
return ExpressionParser.expressionDict.get(expression);
if (ExpressionParser.expressionDict.has({ key: expression })) {
return ExpressionParser.expressionDict.get({ key: expression });
}

const inputStream: ANTLRInputStream = new ANTLRInputStream(expression);
Expand All @@ -297,7 +297,7 @@ export class ExpressionParser implements ExpressionParserInterface {
if (file !== undefined) {
expressionContext = file.expression();
}
ExpressionParser.expressionDict.set(expression, expressionContext);
ExpressionParser.expressionDict.set({ key: expression }, expressionContext);

return expressionContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const languagePolicyKey = Symbol('LanguagePolicy');
* Extension methods for language generator.
*/
export class LanguageGeneratorExtensions {
private static readonly _languageGeneratorManagers = new Map<ResourceExplorer, LanguageGeneratorManager>();
private static readonly _languageGeneratorManagers = new WeakMap<ResourceExplorer, LanguageGeneratorManager>();

/**
* Register default LG file or a language generator as default language generator.
Expand Down

0 comments on commit 5b58d10

Please sign in to comment.