@@ -146,7 +146,7 @@ Connection: Close | |||||
", System.Text.Encoding.UTF8.GetBytes(pac).Length) + pac; | ", System.Text.Encoding.UTF8.GetBytes(pac).Length) + pac; | ||||
byte[] response = System.Text.Encoding.UTF8.GetBytes(text); | byte[] response = System.Text.Encoding.UTF8.GetBytes(text); | ||||
socket.BeginSend(response, 0, response.Length, 0, new AsyncCallback(SendCallback), socket); | socket.BeginSend(response, 0, response.Length, 0, new AsyncCallback(SendCallback), socket); | ||||
Util.Utils.ReleaseMemory(); | |||||
Util.Utils.ReleaseMemory(true); | |||||
} | } | ||||
catch (Exception e) | catch (Exception e) | ||||
{ | { | ||||
@@ -360,7 +360,7 @@ namespace Shadowsocks.Controller | |||||
} | } | ||||
UpdateSystemProxy(); | UpdateSystemProxy(); | ||||
Util.Utils.ReleaseMemory(); | |||||
Util.Utils.ReleaseMemory(true); | |||||
} | } | ||||
@@ -417,7 +417,7 @@ namespace Shadowsocks.Controller | |||||
{ | { | ||||
while (true) | while (true) | ||||
{ | { | ||||
Util.Utils.ReleaseMemory(); | |||||
Util.Utils.ReleaseMemory(false); | |||||
Thread.Sleep(30 * 1000); | Thread.Sleep(30 * 1000); | ||||
} | } | ||||
} | } | ||||
@@ -18,7 +18,7 @@ namespace Shadowsocks | |||||
[STAThread] | [STAThread] | ||||
static void Main() | static void Main() | ||||
{ | { | ||||
Util.Utils.ReleaseMemory(); | |||||
Util.Utils.ReleaseMemory(true); | |||||
using (Mutex mutex = new Mutex(false, "Global\\Shadowsocks_" + Application.StartupPath.GetHashCode())) | using (Mutex mutex = new Mutex(false, "Global\\Shadowsocks_" + Application.StartupPath.GetHashCode())) | ||||
{ | { | ||||
Application.EnableVisualStyles(); | Application.EnableVisualStyles(); | ||||
@@ -10,7 +10,7 @@ namespace Shadowsocks.Util | |||||
{ | { | ||||
public class Utils | public class Utils | ||||
{ | { | ||||
public static void ReleaseMemory() | |||||
public static void ReleaseMemory(bool removePages) | |||||
{ | { | ||||
// release any unused pages | // release any unused pages | ||||
// making the numbers look good in task manager | // making the numbers look good in task manager | ||||
@@ -20,8 +20,29 @@ namespace Shadowsocks.Util | |||||
// which is part of user experience | // which is part of user experience | ||||
GC.Collect(GC.MaxGeneration); | GC.Collect(GC.MaxGeneration); | ||||
GC.WaitForPendingFinalizers(); | GC.WaitForPendingFinalizers(); | ||||
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, | |||||
(UIntPtr)0xFFFFFFFF, (UIntPtr)0xFFFFFFFF); | |||||
if (removePages) | |||||
{ | |||||
// as some users have pointed out | |||||
// removing pages from working set will cause some IO | |||||
// which lowered user experience for another group of users | |||||
// | |||||
// so we do 2 more things here to satisfy them: | |||||
// 1. only remove pages once when configuration is changed | |||||
// 2. add more comments here to tell users that calling | |||||
// this function will not be more frequent than | |||||
// IM apps writing chat logs, or web browsers writing cache files | |||||
// if they're so concerned about their disk, they should | |||||
// uninstall all IM apps and web browsers | |||||
// | |||||
// please open an issue if you're worried about anything else in your computer | |||||
// no matter it's GPU performance, monitor contrast, audio fidelity | |||||
// or anything else in the task manager | |||||
// we'll do as much as we can to help you | |||||
// | |||||
// just kidding | |||||
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, | |||||
(UIntPtr)0xFFFFFFFF, (UIntPtr)0xFFFFFFFF); | |||||
} | |||||
} | } | ||||
public static string UnGzip(byte[] buf) | public static string UnGzip(byte[] buf) | ||||
@@ -322,7 +322,7 @@ namespace Shadowsocks.View | |||||
void configForm_FormClosed(object sender, FormClosedEventArgs e) | void configForm_FormClosed(object sender, FormClosedEventArgs e) | ||||
{ | { | ||||
configForm = null; | configForm = null; | ||||
Util.Utils.ReleaseMemory(); | |||||
Util.Utils.ReleaseMemory(true); | |||||
ShowFirstTimeBalloon(); | ShowFirstTimeBalloon(); | ||||
} | } | ||||