mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-13 02:49:06 +00:00
Aggressive GC after window closed
This commit is contained in:
15
QuickLook/Helpers/ProcessHelper.cs
Normal file
15
QuickLook/Helpers/ProcessHelper.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace QuickLook.Helpers
|
||||
{
|
||||
internal class ProcessHelper
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static void PerformAggressiveGC()
|
||||
{
|
||||
// delay some time to make sure that all windows are closed
|
||||
Task.Delay(1000).ContinueWith(t => GC.Collect(GC.MaxGeneration));
|
||||
}
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
14
QuickLook/Properties/Settings.Designer.cs
generated
14
QuickLook/Properties/Settings.Designer.cs
generated
@@ -8,21 +8,17 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace QuickLook.Properties
|
||||
{
|
||||
namespace QuickLook.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>QuickLook</RootNamespace>
|
||||
<AssemblyName>QuickLook</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
@@ -28,6 +28,7 @@
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>Resources\app.ico</ApplicationIcon>
|
||||
@@ -108,6 +109,7 @@
|
||||
<Compile Include="Helpers\BlurLibrary\PlatformsImpl\Windows8WindowBlurController.cs" />
|
||||
<Compile Include="Helpers\BlurLibrary\PlatformsImpl\WindowsVistaWindowBlurController.cs" />
|
||||
<Compile Include="Helpers\FileHelper.cs" />
|
||||
<Compile Include="Helpers\ProcessHelper.cs" />
|
||||
<Compile Include="MainWindowNoTransparent.cs" />
|
||||
<Compile Include="NativeMethods\Shell32\IShellLink.cs" />
|
||||
<Compile Include="NativeMethods\Shell32\IWshShell.cs" />
|
||||
|
Reference in New Issue
Block a user