Skip to content

Commit

Permalink
fix some memory leak problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jan 21, 2025
1 parent 80e89f7 commit 3db9e49
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 21 deletions.
12 changes: 11 additions & 1 deletion src/Starward/Features/GameLauncher/GameBannerAndPost.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ private void GameBannerAndPost_Unloaded(object sender, RoutedEventArgs e)
{
WeakReferenceMessenger.Default.UnregisterAll(this);
_bannerTimer.Stop();
_bannerTimer.Tick -= _bannerTimer_Tick;
Banners = null;
PostGroups = null;
}


Expand Down Expand Up @@ -201,7 +204,14 @@ private async Task UpdateGameNoticeAlertAsync()
Button_InGameNotices.Visibility = Visibility.Collapsed;
return;
}
IsGameNoticesAlert = await _gameNoticeService.IsNoticeAlertAsync(CurrentGameId.GameBiz);
if (AppSetting.DisableGameNoticeRedHot)
{
IsGameNoticesAlert = false;
}
else
{
IsGameNoticesAlert = await _gameNoticeService.IsNoticeAlertAsync(CurrentGameId.GameBiz);
}
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,6 @@
<Grid Width="40"
Height="40"
CornerRadius="8">
<FontIcon HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"
Glyph="&#xE8A9;"
IsTextScaleFactorEnabled="False" />
<sc:CachedImage Width="40"
Height="40"
Source="{x:Bind CurrentGameBizIcon.GameIcon, FallbackValue={x:Null}}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public GameLauncherSettingDialog()
{
this.InitializeComponent();
this.Loaded += GameLauncherSettingDialog_Loaded;
this.Unloaded += GameLauncherSettingDialog_Unloaded;
}


Expand Down Expand Up @@ -93,7 +94,6 @@ private void FlipView_Settings_Loaded(object sender, RoutedEventArgs e)




private void NavigationView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
{
try
Expand Down Expand Up @@ -133,6 +133,14 @@ private async void GameLauncherSettingDialog_Loaded(object sender, RoutedEventAr
}


private void GameLauncherSettingDialog_Unloaded(object sender, RoutedEventArgs e)
{
LatestPackageGroups = null!;
PreInstallPackageGroups = null!;
FlipView_Settings.Items.Clear();
}




[RelayCommand]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private void CenterInScreen()

private void RootGrid_Loaded(object sender, RoutedEventArgs e)
{
RootGrid.Loaded -= RootGrid_Loaded;
_ = bbsWebBridge.LoadPageAsync();
}

Expand Down
7 changes: 6 additions & 1 deletion src/Starward/Features/GameRecord/GameRecordPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ protected override async void OnLoaded()
protected override void OnUnloaded()
{
WeakReferenceMessenger.Default.UnregisterAll(this);
NavigationViewItem_BattleChronicle.Tapped -= NavigationViewItem_BattleChronicle_Tapped;
NavigationViewItem_UpdateDeviceInfo.Tapped -= NavigationViewItem_UpdateDeviceInfo_Tapped;
CurrentRole = null;
GameRoleList = null!;
}


Expand Down Expand Up @@ -252,7 +256,8 @@ private void InitializeNavigationViewItemVisibility()

public GameRecordRole? CurrentRole
{
get; set
get;
set
{
if (SetProperty(ref field, value))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ protected override async void OnLoaded()



protected override void OnUnloaded()
{
CurrentTheater = null;
TheaterList = null!;
}




[ObservableProperty]
private bool hasData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ protected override async void OnLoaded()



protected override void OnUnloaded()
{
CurrentAbyss = null;
AbyssList = null!;
}



[ObservableProperty]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ protected override async void OnLoaded()
}


protected override void OnUnloaded()
{
CurrentSummary = null!;
SelectMonthData = null;
MonthDataList = null!;
CurrentSeries = null;
SelectSeries = null;
DayDataList = null!;
}



[ObservableProperty]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ protected override async void OnLoaded()



protected override void OnUnloaded()
{
CurrentApocalypticShadow = null;
ApocalypticShadowList = null!;
}



[ObservableProperty]
private List<ApocalypticShadowInfo> apocalypticShadowList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ protected override async void OnLoaded()



protected override void OnUnloaded()
{
CurrentForgottenHall = null;
ForgottenHallList = null!;
}



[ObservableProperty]
private List<ForgottenHallInfo> forgottenHallList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ protected override async void OnLoaded()



protected override void OnUnloaded()
{
CurrentPureFiction = null;
PureFictionList = null!;
}



[ObservableProperty]
private List<PureFictionInfo> pureFictionList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ protected override async void OnLoaded()



protected override void OnUnloaded()
{
BasicInfo = null!;
CurrentRecord = null;
RecordBasicList = null!;
}



[ObservableProperty]
private SimulatedUniverseBasicStats basicInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ protected override async void OnLoaded()



protected override void OnUnloaded()
{
CurrentSummary = null!;
SelectMonthData = null;
MonthDataList = null!;
CurrentSeries = null;
SelectSeries = null;
DayDataList = null!;
}



[ObservableProperty]
private TrailblazeCalendarSummary currentSummary;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ protected override async void OnLoaded()



protected override void OnUnloaded()
{
base.OnUnloaded();
CurrentSummary = null!;
SelectMonthData = null;
MonthDataList = null!;
CurrentSeries = null!;
SelectSeries = null!;
DayDataList = null!;
}


[ObservableProperty]
private InterKnotReportSummary currentSummary;

Expand Down
19 changes: 12 additions & 7 deletions src/Starward/Features/Screenshot/ImageViewWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
</Border.OpacityTransition>
<StackPanel Orientation="Horizontal" Spacing="4">
<!-- 缩小 -->
<Button Width="36"
<Button x:Name="Button_ZoomOut"
Width="36"
Height="36"
Command="{x:Bind ZoomOutCommand}"
Content="&#xE71F;"
Expand All @@ -122,23 +123,25 @@
VerticalAlignment="Center"
HorizontalTextAlignment="Center" />
<!-- 放大 -->
<Button Width="36"
<Button x:Name="Button_ZoomIn"
Width="36"
Height="36"
Command="{x:Bind ZoomInCommand}"
Content="&#xE8A3;"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}"
ToolTipService.ToolTip="{x:Bind lang:Lang.ImageViewPage_ZoomIn}" />
<!-- 旋转 -->
<Button Width="36"
<Button x:Name="Button_Rotate"
Width="36"
Height="36"
Command="{x:Bind RotateCommand}"
Content="&#xE7AD;"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}"
ToolTipService.ToolTip="{x:Bind lang:Lang.ImageViewPage_Rotate}" />
<!-- 全屏 -->
<Button Name="Button_FullScreen"
<Button x:Name="Button_FullScreen"
Width="36"
Height="36"
Command="{x:Bind FullScreenCommand}"
Expand All @@ -148,7 +151,7 @@
ToolTipService.ToolTip="{x:Bind lang:Lang.GameSettingPage_FullScreen}" />
<AppBarSeparator Padding="0" />
<!-- 复制 -->
<Button x:Name="_Button_Copy"
<Button x:Name="Button_Copy"
Width="36"
Height="36"
Command="{x:Bind CopyImageCommand}"
Expand All @@ -163,15 +166,17 @@
</Button.ContentTransitions>
</Button>
<!-- 打开 -->
<Button Width="36"
<Button x:Name="Button_OpenFile"
Width="36"
Height="36"
Command="{x:Bind OpenFileCommand}"
Content="&#xE8E5;"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}"
ToolTipService.ToolTip="{x:Bind lang:Lang.Common_Open}" />
<!-- 关闭 -->
<Button Width="36"
<Button x:Name="Button_Close"
Width="36"
Height="36"
Command="{x:Bind CloseCommand}"
Content="&#xE711;"
Expand Down
34 changes: 29 additions & 5 deletions src/Starward/Features/Screenshot/ImageViewWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ public ImageViewWindow()
{
this.InitializeComponent();
InitializeWindow();
this.Closed += ImageViewWindow_Closed;
}





private void InitializeWindow()
{
Title = "Starward Screenshots Viewer";
Expand All @@ -63,6 +62,31 @@ private void InitializeWindow()
}


// ImageViewWindow 内存泄漏的问题还无法解决
private void ImageViewWindow_Closed(object sender, WindowEventArgs args)
{
RootGrid.KeyDown -= RootGrid_KeyDown;
_Image.SizeChanged -= _Image_SizeChanged;
_Image.ImageExOpened -= _Image_ImageOpened;
_ScrollViewer_Image.DoubleTapped -= _ScrollViewer_Image_DoubleTapped;
_ScrollViewer_Image.PointerMoved -= _ScrollViewer_Image_PointerMoved;
_ScrollViewer_Image.PointerPressed -= _ScrollViewer_Image_PointerPressed;
_ScrollViewer_Image.PointerReleased -= _ScrollViewer_Image_PointerReleased;
_ScrollViewer_Image.PointerWheelChanged -= _ScrollViewer_Image_PointerWheelChanged;
_ScrollViewer_Image.Tapped -= _ScrollViewer_Image_Tapped;
_ScrollViewer_Image.ViewChanged -= _ScrollViewer_Image_ViewChanged;
Button_Close.Command = null;
Button_Copy.Command = null;
Button_FullScreen.Command = null;
Button_OpenFile.Command = null;
Button_Rotate.Command = null;
Button_ZoomOut.Command = null;
Button_ZoomIn.Command = null;
CurrentImage = null!;
ImageCollection = null;
this.Bindings.StopTracking();
}



private void RootGrid_KeyDown(object sender, KeyRoutedEventArgs e)
Expand Down Expand Up @@ -250,9 +274,9 @@ private async Task CopyImageAsync()
else
{
ClipboardHelper.SetStorageItems(DataPackageOperation.Copy, file);
_Button_Copy.Content = "\xE8FB";
Button_Copy.Content = "\xE8FB";
await Task.Delay(3000);
_Button_Copy.Content = "\xE8C8";
Button_Copy.Content = "\xE8C8";
}
}
catch (Exception ex)
Expand Down Expand Up @@ -304,7 +328,7 @@ private async Task OpenFileAsync()
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void _ScrollViewer_Image_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
private void _ScrollViewer_Image_ViewChanged(object? sender, ScrollViewerViewChangedEventArgs e)
{
_TextBlock_Factor.Text = (_ScrollViewer_Image.ZoomFactor * UIScale).ToString("P0");
}
Expand Down
1 change: 0 additions & 1 deletion src/Starward/Features/Screenshot/ScreenshotPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ protected override async void OnLoaded()
protected override void OnUnloaded()
{
Watcher?.Dispose();
GC.Collect();
}


Expand Down
6 changes: 6 additions & 0 deletions src/Starward/Features/SelfQuery/SelfQueryPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ protected override async void OnLoaded()
protected override void OnUnloaded()
{
tokenSource?.Cancel();
GenshinQueryItemList = null;
StarRailQueryItemList = null;
ZZZQueryItemList = null;
QueryUserInfo = null;
SelectTypeStats = null!;
TypeStatsList = null!;
}


Expand Down
Loading

0 comments on commit 3db9e49

Please sign in to comment.