diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index a15d78906..8b56fa03e 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -908,6 +908,10 @@ export class AstFilterParser { this.scriptletArgListParser = new ArgListParser(','); } + finish() { + this.selectorCompiler.finish(); + } + parse(raw) { this.raw = raw; this.rawEnd = raw.length; @@ -3229,6 +3233,14 @@ class ExtSelectorCompiler { this.error = undefined; } + // CSSTree library holds onto last string parsed, and this is problematic + // when the string is a slice of a huge parent string (typically a whole + // filter lists), it causes the huge parent string to stay in memory. + // Asking CSSTree to parse an empty string resolves this issue. + finish() { + cssTree.parse(''); + } + compile(raw, out, compileOptions = {}) { this.asProcedural = compileOptions.asProcedural === true; diff --git a/src/js/storage.js b/src/js/storage.js index 730338382..e59b79558 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -1102,6 +1102,7 @@ import { } compiler.finish(writer); + parser.finish(); // https://github.com/uBlockOrigin/uBlock-issues/issues/1365 // Embed version into compiled list itself: it is encoded in as the