Aggressive GC after window closed

This commit is contained in:
Paddy Xu
2017-05-28 15:59:31 +03:00
parent 7e95d5ea2b
commit 3768470a33
4 changed files with 38 additions and 18 deletions

View File

@@ -4,10 +4,12 @@ using System.IO;
using System.Runtime.ExceptionServices;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Threading;
using QuickLook.Helpers;
using QuickLook.Helpers.BlurLibrary;
using QuickLook.Plugin;
using KeyEventArgs = System.Windows.Forms.KeyEventArgs;
namespace QuickLook
{
@@ -81,15 +83,12 @@ namespace QuickLook
internal void UnloadPlugin()
{
// clear ref to control
//container.Content = null;
ContextObject.Reset();
_plugin?.Cleanup();
_plugin = null;
GC.Collect();
ProcessHelper.PerformAggressiveGC();
}
internal void BeginShow(IViewer matchedPlugin, string path)
@@ -97,6 +96,8 @@ namespace QuickLook
_path = path;
_plugin = matchedPlugin;
ContextObject.ViewerWindow = this;
// get window size before showing it
_plugin.Prepare(path, ContextObject);
@@ -150,8 +151,14 @@ namespace QuickLook
internal void BeginHide()
{
// the focused element will not processed by GC: https://stackoverflow.com/questions/30848939/memory-leak-due-to-window-efectivevalues-retention
FocusManager.SetFocusedElement(this, null);
Keyboard.ClearFocus();
UnloadPlugin();
Hide();
ProcessHelper.PerformAggressiveGC();
}
}
}