[AdvPaste]Clear image sources to fix memory leak (#33438)

* [AdvancedPaste] Clear image sources to fix memory leak
This commit is contained in:
Stefan Markovic 2024-06-19 17:53:39 +02:00 committed by GitHub
parent 5c631bd2c7
commit dcbff83d8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using AdvancedPaste.Helpers; using AdvancedPaste.Helpers;
@ -86,6 +87,11 @@ namespace AdvancedPaste.Pages
_dispatcherQueue.TryEnqueue(async () => _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(); clipboardHistory.Clear();
foreach (var item in items) foreach (var item in items)