From dcbff83d8c834391bb033c5a431748c8fe7d1a54 Mon Sep 17 00:00:00 2001 From: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com> Date: Wed, 19 Jun 2024 17:53:39 +0200 Subject: [PATCH] [AdvPaste]Clear image sources to fix memory leak (#33438) * [AdvancedPaste] Clear image sources to fix memory leak --- .../AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml.cs b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml.cs index 1aa49c1014..8926cb1820 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Pages/MainPage.xaml.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; using System.Threading; using System.Threading.Tasks; using AdvancedPaste.Helpers; @@ -86,6 +87,11 @@ namespace AdvancedPaste.Pages _dispatcherQueue.TryEnqueue(async () => { + // Clear to avoid leaks due to Garbage Collection not clearing the bitmap from memory. Fix for https://github.com/microsoft/PowerToys/issues/33423 + clipboardHistory.Where(x => x.Image is not null) + .ToList() + .ForEach(x => x.Image.ClearValue(BitmapImage.UriSourceProperty)); + clipboardHistory.Clear(); foreach (var item in items)