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

Memory leak and other issues when saving settings #10609

Open
mimvdb opened this issue Jul 11, 2021 · 9 comments
Open

Memory leak and other issues when saving settings #10609

mimvdb opened this issue Jul 11, 2021 · 9 comments
Labels
Area-Settings UI Anything specific to the SUI External-Blocked-WinUI3 We can't progress until WinUI3 exists. Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal.
Milestone

Comments

@mimvdb
Copy link
Contributor

mimvdb commented Jul 11, 2021

Windows Terminal version (or Windows build number)

1.8.1521.0 (also observed on source build 2021-07-11)

Other Software

No response

Steps to reproduce

Open the settings dialog and spam click save. No option needs to be changed.

Video: 13 seconds in, the settings could not be reloaded from file (not sure if it is not loading or file corruption).
https://user-images.githubusercontent.com/2277504/125179830-a31f3a00-e1f2-11eb-8b6f-6f6aa07896c5.mp4

Expected Behavior

Memory stays roughly the same, settings file can be loaded after saving, main UI does not extend past its borders.

Actual Behavior

Memory grows and is not reclaimed, settings file can sometimes not be loaded after saving, UI grows past its borders during reloading.

(Second and third only discovered after deciding to record a video for the memory leak)

Not sure if you want separate tracking issues for these, let me know.

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jul 11, 2021
@zadjii-msft zadjii-msft added Area-Settings UI Anything specific to the SUI Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. labels Jul 12, 2021
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Jul 12, 2021
@zadjii-msft zadjii-msft added this to the Terminal v2.0 milestone Jul 12, 2021
@zadjii-msft
Copy link
Member

Not sure if you want separate tracking issues for these, let me know.

Typically, yea, we'd prefer separate issues, but since you've already got #10619 open for the overflow bit, we can just leave this open for the memory leak. I've got a strong suspicion that the memory leak and the "failed to load settings" dialog will end up with the same root cause ☺️

ghost pushed a commit that referenced this issue Jul 12, 2021
When navigating the settings (or saving/discarding) the animation of the main content overflows the bar with the save and discard buttons. If the main content is encapsulated in a ScrollView the issue goes away.

Fixes one of the issues in #10609

## Validation Steps Performed
Clicked around a whole bunch and have not seen the overflow happen again. Verified that on tabs where scroll is necessary it can still be scrolled, and reflow of elements still functions.
@mimvdb
Copy link
Contributor Author

mimvdb commented Jul 12, 2021

Unfortunately the question here seems to be what doesn't leak.

  • The settings.Copy() doesn't seem to leak 😄
  • Determining selectedItemTag

Besides that pretty much any interaction the MainPage::UpdateSettings has with the UI causes the growing memory as seen in the video. Some particulars:

  • Any call to _Navigate seems to leak, setting the CacheSize of the contentFrame to 0 doesn't help
  • Calls that manipulate the menuItems such as menuItems.ReplaceAll or Clear/Append leak even when the same elements are used
  • Calling ReplaceAll twice or Clear/Appending multiple times back to back causes a crash for some reason

I'm stopping my investigation here. Perhaps it is easier to debug with access to the Windows.UI.* source if the terminal team has access?

DHowett pushed a commit that referenced this issue Jul 12, 2021
When navigating the settings (or saving/discarding) the animation of the main content overflows the bar with the save and discard buttons. If the main content is encapsulated in a ScrollView the issue goes away.

Fixes one of the issues in #10609

## Validation Steps Performed
Clicked around a whole bunch and have not seen the overflow happen again. Verified that on tabs where scroll is necessary it can still be scrolled, and reflow of elements still functions.

(cherry picked from commit 19f8b9c)
@mimvdb
Copy link
Contributor Author

mimvdb commented Jul 16, 2021

I couldn't resist taking another look. It seems the main (or only) issue is navigating the pages. (The menuItems.ReplaceAll might implicitly navigate, and calling it twice crashing might be an unrelated issue)

Interestingly, some pages leak way more than others. For example, on 1.8.1521.0, the "color schemes" page leaks hardly anything while the "actions" page seems to leak more than a megabyte per click on "discard".

A debug build on main shows "color schemes" also leaking, and makes the "actions" page leak about 5MB per navigation.

I'll file a separate issue for the settings file not loading, as that seems less related now.

ghost pushed a commit that referenced this issue Jul 20, 2021
## Summary of the Pull Request
Add an explicit background color to part of the settings UI to prevent animation overflow. The previous solution (adding a ScrollViewer) caused problems.

## References
#10619 adds a ScrollViewer for one of the issues in #10609

## PR Checklist
* [x] Closes #10664
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] Tests added/passed
* [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx
* [ ] Schema updated.
* [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

## Detailed Description of the Pull Request / Additional comments

## Validation Steps Performed
Visually confirmed the animation doesn't overflow, changed the theme and confirmed the colors are responsive. Confirmed the extra scrollbar is gone.
@DHowett DHowett removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Jul 22, 2021
DHowett pushed a commit that referenced this issue Aug 25, 2021
## Summary of the Pull Request
Add an explicit background color to part of the settings UI to prevent animation overflow. The previous solution (adding a ScrollViewer) caused problems.

## References
#10619 adds a ScrollViewer for one of the issues in #10609

## PR Checklist
* [x] Closes #10664
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] Tests added/passed
* [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx
* [ ] Schema updated.
* [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

## Detailed Description of the Pull Request / Additional comments

## Validation Steps Performed
Visually confirmed the animation doesn't overflow, changed the theme and confirmed the colors are responsive. Confirmed the extra scrollbar is gone.
@zadjii-msft zadjii-msft modified the milestones: Terminal v2.0, 22H1 Jan 4, 2022
@zadjii-msft zadjii-msft modified the milestones: 22H1, Terminal v1.14 Feb 2, 2022
@zadjii-msft
Copy link
Member

Maybe related:

I could have sworn I saw another related issue yesterday, but I'm having a hard time finding it now

@zadjii-msft
Copy link
Member

Okay, I've got a VS diag session in D:\dev\gh-10609\Report20220316-1134.diagsession. I'm not totally sure how to read this, so bear with me:

image
image

Looks like half of the 8MB that got allocated by saving the menu a few times were random ntdll allocations. The other half look like TermControls, so maybe we're accidentally leaking the preview controls somehow. Where are we taking a strong ref when it should be a weak...?

@zadjii-msft
Copy link
Member

1005e0d makes this a bit better, but there's still some leakage. Here's the deal though - there's leakage even in the XAML Controls Gallery with the nav view.

@zadjii-msft
Copy link
Member

image
So in this comparison, there was +3MB in DispatchMessageWorker, so I click on that frame, and then below that shows a bunch of RtlpAllocateHeapInternal calls, that all expando to point at Windows.UI.Xaml.dll. So, it's not us?

@zadjii-msft
Copy link
Member

"D:\dev\gh-10609\Report20220316-1640 (2).diagsession" has two snapshots, both with +780KB on a single save of the SUI.

@zadjii-msft zadjii-msft modified the milestones: Terminal v1.14, 22H2 Apr 28, 2022
@zadjii-msft zadjii-msft modified the milestones: 22H2, Backlog Dec 5, 2022
@zadjii-msft
Copy link
Member

Seems like this is still present on 1.22 canary builds. Even after closing the SUI, the XAML objects remain leaked.

Amazingly enough, I think this might be fixed in WinUI 3. The WinUI 2 gallery repros this pretty readily, just switching pages in the NavView page. But the WinUI 3 gallery didn't seem to.

@zadjii-msft zadjii-msft added the External-Blocked-WinUI3 We can't progress until WinUI3 exists. label Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings UI Anything specific to the SUI External-Blocked-WinUI3 We can't progress until WinUI3 exists. Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

No branches or pull requests

3 participants