Skip to content

Commit b4226bc

Browse files
authored
Merge pull request #4910 from Tyriar/tyriar/leaks
Help embedders avoid memory leaks by clearing options
2 parents fb2c39c + 1943636 commit b4226bc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/browser/Linkifier2.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export class Linkifier2 extends Disposable implements ILinkifier2 {
3939
this.register(getDisposeArrayDisposable(this._linkCacheDisposables));
4040
this.register(toDisposable(() => {
4141
this._lastMouseEvent = undefined;
42+
// Clear out link providers as they could easily cause an embedder memory leak
43+
this._linkProviders.length = 0;
44+
this._activeProviderReplies?.clear();
4245
}));
4346
// Listen to resize to catch the case where it's resized and the cursor is out of the viewport.
4447
this.register(this._bufferService.onResize(() => {

src/common/services/OptionsService.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { EventEmitter } from 'common/EventEmitter';
7-
import { Disposable } from 'common/Lifecycle';
7+
import { Disposable, toDisposable } from 'common/Lifecycle';
88
import { isMac } from 'common/Platform';
99
import { CursorStyle, IDisposable } from 'common/Types';
1010
import { FontWeight, IOptionsService, ITerminalOptions } from 'common/services/Services';
@@ -86,6 +86,13 @@ export class OptionsService extends Disposable implements IOptionsService {
8686
this.rawOptions = defaultOptions;
8787
this.options = { ... defaultOptions };
8888
this._setupOptions();
89+
90+
// Clear out options that could link outside xterm.js as they could easily cause an embedder
91+
// memory leak
92+
this.register(toDisposable(() => {
93+
this.rawOptions.linkHandler = null;
94+
this.rawOptions.documentOverride = null;
95+
}));
8996
}
9097

9198
// eslint-disable-next-line @typescript-eslint/naming-convention

0 commit comments

Comments
 (0)