Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing disposals #155976

Merged
merged 2 commits into from
Jul 25, 2022
Merged

Add missing disposals #155976

merged 2 commits into from
Jul 25, 2022

Conversation

SvanT
Copy link
Contributor

@SvanT SvanT commented Jul 22, 2022

#155232

I did some V8 heap profiling and found a few more places where
references to closed terminals prevents them from being garbage
collected.

@ghost
Copy link

ghost commented Jul 22, 2022

CLA assistant check
All CLA requirements met.

@SvanT
Copy link
Contributor Author

SvanT commented Jul 22, 2022

@Tyriar I think there is at least one more retainer than these ones which is the action bar button actions (split/kill terminal) inside the terminal tabs list:
image

One guess is that the registration of the DOM mousedown/tap events doesn't get disposed when the terminal is closed, and more and more event registrations referencing terminals are being done in the action bar without being cleaned up when terminals are closed.

But I get a bit lost in the disposals at this time...

@Tyriar
Copy link
Member

Tyriar commented Jul 22, 2022

Thanks again for this, these PRs are great! We do a big cleanup every now and then when we notice something is off, not sure how we could test to prevent regressions 🤔

I think we could fix this by adding actions here:

const actions = [
new Action(TerminalCommandId.SplitInstance, terminalStrings.split.short, ThemeIcon.asClassName(Codicon.splitHorizontal), true, async () => {
this._runForSelectionOrInstance(instance, async e => {
this._terminalService.createTerminal({ location: { parentTerminal: e } });
});
}),
new Action(TerminalCommandId.KillInstance, terminalStrings.kill.short, ThemeIcon.asClassName(Codicon.trashcan), true, async () => {
this._runForSelectionOrInstance(instance, e => this._terminalService.safeDisposeTerminal(e));
})
];

To template.elementDisposables?

@Tyriar Tyriar added this to the July 2022 milestone Jul 22, 2022
Tyriar
Tyriar previously requested changes Jul 22, 2022
Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if that template.elementDisposables idea doesn't work

@SvanT
Copy link
Contributor Author

SvanT commented Jul 22, 2022

@Tyriar Nope, chaning from line 484 to this:

		if (!template.elementDisposables) {
			template.elementDisposables = new DisposableStore();
		}

		for (const action of actions) {
			template.actionBar.push(action, { icon: true, label: false, keybinding: this._keybindingService.lookupKeybinding(action.id)?.getLabel() });
			template.elementDisposables.add(action);
		}

Doesn't seem to change anything, the retainer still looks like the screenshot in my last comment.

@SvanT
Copy link
Contributor Author

SvanT commented Jul 22, 2022

Removing the template.actionBar.push line seems to solve it, but there is pretty much going on in the actionbar push function

@Tyriar Tyriar requested a review from meganrogge July 22, 2022 20:13
@SvanT
Copy link
Contributor Author

SvanT commented Jul 23, 2022

@Tyriar I found it!

Action bars are not disposed when a terminal is closed, they are cached in the list until you open a new terminal, so manually clear it to make it possible to garbage collect the closed terminal directly.

@SvanT SvanT requested a review from Tyriar July 23, 2022 10:50
SvanT added 2 commits July 23, 2022 12:53
I did some V8 heap profiling and found a few more places where
references to closed terminals prevents them from being garbage
collected.
Action bars are not disposed when a terminal is closed, they are cached
in the list until you open a new terminal, so manually clear it to make
it possible to garbage collect the closed terminal directly.
@meganrogge meganrogge enabled auto-merge (squash) July 25, 2022 15:52
@meganrogge meganrogge dismissed Tyriar’s stale review July 25, 2022 15:53

addressed the feedback

@meganrogge meganrogge merged commit c4141cf into microsoft:main Jul 25, 2022
@SvanT SvanT deleted the fix-terminal-disposal branch July 25, 2022 18:05
@github-actions github-actions bot locked and limited conversation to collaborators Sep 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants