mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-01-13 07:46:23 +01:00
Compare commits
4 Commits
stable
...
shawn/fixQ
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e0ebfd6db | ||
|
|
3d510dc382 | ||
|
|
8ffd88fdf3 | ||
|
|
097cf7414b |
@@ -19,6 +19,8 @@ public sealed partial class AppsListPage : Page
|
||||
public AppsListPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
NavigationCacheMode = NavigationCacheMode.Disabled;
|
||||
Unloaded += OnUnloaded;
|
||||
}
|
||||
|
||||
public AllAppsViewModel ViewModel { get; private set; } = default!;
|
||||
@@ -36,6 +38,30 @@ public sealed partial class AppsListPage : Page
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
|
||||
{
|
||||
base.OnNavigatingFrom(e);
|
||||
CleanupPage();
|
||||
}
|
||||
|
||||
private void OnUnloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CleanupPage();
|
||||
}
|
||||
|
||||
private void CleanupPage()
|
||||
{
|
||||
// Clear the collection before cleaning up to release all item references
|
||||
if (ViewModel != null)
|
||||
{
|
||||
ViewModel.FlyoutMenuItems.Clear();
|
||||
}
|
||||
|
||||
DataContext = null;
|
||||
ViewModel = null!;
|
||||
_context = null;
|
||||
}
|
||||
|
||||
private void BackButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_context == null || Frame == null)
|
||||
|
||||
@@ -27,6 +27,7 @@ public sealed partial class LaunchPage : Page
|
||||
public LaunchPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
NavigationCacheMode = NavigationCacheMode.Disabled;
|
||||
}
|
||||
|
||||
public LauncherViewModel ViewModel { get; private set; } = default!;
|
||||
@@ -44,6 +45,12 @@ public sealed partial class LaunchPage : Page
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
|
||||
{
|
||||
base.OnNavigatingFrom(e);
|
||||
DataContext = null;
|
||||
}
|
||||
|
||||
private void SettingsBtn_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_coordinator?.OpenSettings();
|
||||
|
||||
@@ -65,4 +65,16 @@ public sealed partial class ShellPage : Page
|
||||
appsListPage.ViewModel?.RefreshSettings();
|
||||
}
|
||||
}
|
||||
|
||||
internal void NavigateToLaunchIfNeeded()
|
||||
{
|
||||
// Always clear FlyoutMenuItems to release memory
|
||||
_allAppsViewModel?.FlyoutMenuItems.Clear();
|
||||
|
||||
// Navigate back to LaunchPage if on AppsListPage
|
||||
if (ContentFrame.Content is AppsListPage)
|
||||
{
|
||||
NavigateToLaunch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,8 +143,11 @@ public sealed partial class MainWindow : WindowEx, IDisposable
|
||||
_trimCts = new CancellationTokenSource();
|
||||
var token = _trimCts.Token;
|
||||
|
||||
// Delay the trim to avoid aggressive GC during quick toggles
|
||||
Task.Delay(2000, token).ContinueWith(
|
||||
// Delay memory trim for 5 seconds to avoid aggressive GC during quick toggles.
|
||||
// A shorter delay (previously 2 seconds) caused heavy UI (e.g. AppsListPage) to be
|
||||
// torn down and rebuilt when users quickly reopened the window, which hurt perceived
|
||||
// responsiveness more than the extra few seconds of retained memory.
|
||||
Task.Delay(5000, token).ContinueWith(
|
||||
_ =>
|
||||
{
|
||||
if (token.IsCancellationRequested)
|
||||
@@ -152,7 +155,24 @@ public sealed partial class MainWindow : WindowEx, IDisposable
|
||||
return;
|
||||
}
|
||||
|
||||
TrimMemory();
|
||||
_dispatcherQueue.TryEnqueue(() =>
|
||||
{
|
||||
// Navigate back to LaunchPage before memory trim to release AppsListPage resources
|
||||
ShellHost.NavigateToLaunchIfNeeded();
|
||||
|
||||
// Give UI time to complete cleanup before forcing GC
|
||||
Task.Delay(500, token).ContinueWith(
|
||||
__ =>
|
||||
{
|
||||
if (!token.IsCancellationRequested)
|
||||
{
|
||||
_dispatcherQueue.TryEnqueue(TrimMemory);
|
||||
}
|
||||
},
|
||||
token,
|
||||
TaskContinuationOptions.None,
|
||||
TaskScheduler.Default);
|
||||
});
|
||||
},
|
||||
token,
|
||||
TaskContinuationOptions.None,
|
||||
|
||||
@@ -154,6 +154,9 @@ public sealed class AllAppsViewModel : Observable
|
||||
if (_coordinator.UpdateModuleEnabled(flyoutItem.Tag, flyoutItem.IsEnabled))
|
||||
{
|
||||
_coordinator.NotifyUserSettingsInteraction();
|
||||
|
||||
// Trigger re-sort immediately when status changes on UI
|
||||
RefreshFlyoutMenuItems();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user