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

Prevent Tab Switcher from increasing Tab refcount #8653

Merged
2 commits merged into from
Jan 4, 2021

Conversation

Don-Vito
Copy link
Contributor

@Don-Vito Don-Vito commented Dec 25, 2020

Fix TabPaletteItem to hold only a weak reference to a tab.
This way we guarantee that the refcount of the closed tab
gets to 0 immediately
(and that command palette cannot "raise it from the dead").

While this seems a correct thing to do,
it is still not clear why the FilteredCommand itself
(the one holding the TabPaletteItem) doesn't get released
until the UI is refreshed.

There is an impact of not registering to PropertyChanged event:
if the tab title changes during Tab Switcher navigation
the Tab Switcher item won't be updated immediately
(the change will apply next time the Tab Switcher is open).

Due to this change we need to make sure that the tabs binding
in #8427
doesn't break the title / icon update.

Validation Steps Performed

  • Manual testing

Closes #8651

Comment on lines 27 to 43
_tabChangedRevoker = tab.PropertyChanged(winrt::auto_revoke, [weakThis{ get_weak() }](auto& sender, auto& e) {
auto item{ weakThis.get() };
auto senderTab{ sender.try_as<TabBase>() };

if (item && senderTab)
{
auto changedProperty = e.PropertyName();
if (changedProperty == L"Title")
{
item->Name(senderTab.Title());
}
else if (changedProperty == L"Icon")
{
item->Icon(senderTab.Icon());
}
}
});
Copy link
Member

Choose a reason for hiding this comment

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

are we going to be upset that we don't have this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DHowett - happy new year! Missed you! 😊

Yes, we will be a upset a bit, as if the switcher is already visible the change in the tab's name / icon won't get reflected immediately. The update will become visible only the next time the tab switcher is open.

We definitely need to find a solution for this, but I assumed this one is urgent enough to restore the functionality in some follow up.

@DHowett DHowett self-assigned this Jan 1, 2021
@zadjii-msft zadjii-msft self-assigned this Jan 4, 2021
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

I'm surprised that we need to remove the _tab.PropertyChanged handler too. I'd expect that wouldn't create a strong ref to the Tab - that kinda makes me worried that we have other such leaks elsewhere

@zadjii-msft zadjii-msft removed their assignment Jan 4, 2021
@Don-Vito
Copy link
Contributor Author

Don-Vito commented Jan 4, 2021

I'm surprised that we need to remove the _tab.PropertyChanged handler too. I'd expect that wouldn't create a strong ref to the Tab - that kinda makes me worried that we have other such leaks elsewhere

@zadjii-msft - know what.. I only read about this.. but never tried not to remove. I will check and update you.

UPDATE: It works.. 🤦 I think I was confused.. as I started with making FilteredCommand::Item to be weak ref. And in this case I could not make items implement INotifyPropertyChanged, as the binding will increase the refcount (it needs to store it). However, it is irrelevant here as actually the Item remained strong-ref and only the Tab is weak.

@Don-Vito Don-Vito requested a review from DHowett January 4, 2021 18:24
@ghost ghost added Area-User Interface Issues pertaining to the user interface of the Console or Terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. Severity-Blocking We won't ship a release like this! No-siree. labels Jan 4, 2021
@DHowett
Copy link
Member

DHowett commented Jan 4, 2021

I love this. Thanks so much. Happy new year indeed!

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jan 4, 2021
@ghost
Copy link

ghost commented Jan 4, 2021

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 68e0af4 into microsoft:main Jan 4, 2021
@ghost
Copy link

ghost commented Jan 28, 2021

🎉Windows Terminal Preview v1.6.10272.0 has been released which incorporates this pull request.:tada:

Handy links:

@ghost ghost mentioned this pull request Jan 28, 2021
mpela81 pushed a commit to mpela81/terminal that referenced this pull request Jan 28, 2021
Fix `TabPaletteItem` to hold only a weak reference to a tab.
This way we guarantee that the refcount of the closed tab 
gets to 0 immediately
(and that command palette cannot "raise it from the dead").

While this seems a correct thing to do, 
it is still not clear why the `FilteredCommand` itself 
(the one holding the `TabPaletteItem`) doesn't get released
until the UI is refreshed.

There is an impact of not registering to PropertyChanged event:
if the tab title changes during Tab Switcher navigation
the Tab Switcher item won't be updated immediately
(the change will apply next time the Tab Switcher is open).

Due to this change we need to make sure that the tabs binding
in microsoft#8427
doesn't break the title / icon update.

## Validation Steps Performed
* Manual testing

Closes microsoft#8651
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-User Interface Issues pertaining to the user interface of the Console or Terminal AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. Severity-Blocking We won't ship a release like this! No-siree.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tabs are not released by TabSwitcher
3 participants