Help embedders avoid memory leaks by clearing options

Related microsoft/vscode#192838
This commit is contained in:
Daniel Imms
2023-12-08 12:14:22 -08:00
parent fb2c39cb57
commit 1943636f02
2 changed files with 11 additions and 1 deletions
+3
View File
@@ -39,6 +39,9 @@ export class Linkifier2 extends Disposable implements ILinkifier2 {
this.register(getDisposeArrayDisposable(this._linkCacheDisposables));
this.register(toDisposable(() => {
this._lastMouseEvent = undefined;
// Clear out link providers as they could easily cause an embedder memory leak
this._linkProviders.length = 0;
this._activeProviderReplies?.clear();
}));
// Listen to resize to catch the case where it's resized and the cursor is out of the viewport.
this.register(this._bufferService.onResize(() => {
+8 -1
View File
@@ -4,7 +4,7 @@
*/
import { EventEmitter } from 'common/EventEmitter';
import { Disposable } from 'common/Lifecycle';
import { Disposable, toDisposable } from 'common/Lifecycle';
import { isMac } from 'common/Platform';
import { CursorStyle, IDisposable } from 'common/Types';
import { FontWeight, IOptionsService, ITerminalOptions } from 'common/services/Services';
@@ -86,6 +86,13 @@ export class OptionsService extends Disposable implements IOptionsService {
this.rawOptions = defaultOptions;
this.options = { ... defaultOptions };
this._setupOptions();
// Clear out options that could link outside xterm.js as they could easily cause an embedder
// memory leak
this.register(toDisposable(() => {
this.rawOptions.linkHandler = null;
this.rawOptions.documentOverride = null;
}));
}
// eslint-disable-next-line @typescript-eslint/naming-convention