unload terminals when they go out of view to save memory

This commit is contained in:
sawka
2022-09-08 13:44:24 -07:00
parent 400815a622
commit 677a60d735
3 changed files with 26 additions and 4 deletions
+20 -3
View File
@@ -216,11 +216,12 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
}
visibilityChanged(vis : boolean) : void {
if (vis && !this.termLoaded.get()) {
let curVis = this.termLoaded.get();
if (vis && !curVis) {
this.loadTerminal();
}
else if (!vis && this.termLoaded.get()) {
let {line} = this.props;
else if (!vis && curVis) {
this.unloadTerminal();
}
}
@@ -240,6 +241,22 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
sw.connectElem(termElem, cmd, this.props.width);
mobx.action(() => this.termLoaded.set(true))();
}
unloadTerminal() : void {
let {sw, line} = this.props;
let model = GlobalModel;
let cmd = model.getCmd(line);
if (cmd == null) {
return;
}
let termId = "term-" + getLineId(line);
sw.disconnectElem(line.cmdid);
mobx.action(() => this.termLoaded.set(false))();
let termElem = document.getElementById(termId);
if (termElem != null) {
termElem.replaceChildren();
}
}
componentDidMount() {
let {line} = this.props;
+1 -1
View File
@@ -329,7 +329,7 @@ class ScreenWindow {
disconnectElem(cmdId : string) {
let termWrap = this.terms[cmdId];
if (cmdId != null) {
if (termWrap != null) {
termWrap.dispose();
delete this.terms[cmdId];
}
+5
View File
@@ -219,10 +219,15 @@ class TermWrap {
}
this.dataUpdates = [];
}, delayMs);
}).catch((e) => {
console.log("error reloading terminal", e);
});
}
updatePtyData(pos : number, data : Uint8Array) {
if (this.terminal == null) {
return;
}
if (this.loadError.get()) {
return;
}