Skip to content

Commit eab8bba

Browse files
fix(harper.js): create disposal function and use it (#2445)
* test(harper.js): in firefox * test(harper.js): to ensure that memory does not leak with minimal loops * test(harper-wasm): that the issue is not in the WebAssembly code * test(harper.js): make the test fail when memory is used * potential fix * chore: `just format` * fix: dispose `Linter` properly in Obsidian and the Web Extension * fix(chrome-ext): return Serializer test to its rightful place * fix: revert changes to the example * fix(harper.js): clean up trash * chore: `just format` * fix(harper.js): bad interface method * fix(harper.js): dispose `OrganizedGroup` objects and the linters in the tests * fix(harper.js): make test only run for the `LocalLinter`
1 parent 9ae6a07 commit eab8bba

10 files changed

Lines changed: 162 additions & 33 deletions

File tree

Cargo.lock

Lines changed: 15 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

harper-wasm/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,4 +659,19 @@ mod tests {
659659
let lints = linter.lint(text, Language::Plain, false);
660660
assert!(lints.is_empty());
661661
}
662+
663+
#[test]
664+
fn does_not_oom_with_repeated_lints() {
665+
for _ in 0..3000 {
666+
let mut linter = Linter::new(Dialect::American);
667+
668+
let results = linter.lint(
669+
"This is a grammatically correct sentence.".to_string(),
670+
Language::Plain,
671+
false,
672+
);
673+
674+
assert!(results.is_empty())
675+
}
676+
}
662677
}

packages/chrome-plugin/src/background/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ async function setActivationKey(key: ActivationKey) {
394394
}
395395

396396
function initializeLinter(dialect: Dialect) {
397+
if (linter != null) {
398+
linter.dispose();
399+
}
400+
397401
linter = new LocalLinter({
398402
binary: BinaryModule.create(chrome.runtime.getURL('./wasm/harper_wasm_bg.wasm')),
399403
dialect,

0 commit comments

Comments
 (0)