I'm using the code below to free up memory on some running programs because my own program needs large memory resources to run faster.
[DllImport("psapi.dll")]
public static extern bool EmptyWorkingSet(IntPtr hProcess);
public FreeMem(string programName){
EmptyWorkingSet(Process.GetCurrentProcess().Handle);
foreach(Process process in Process.GetProcesses(programName))
{
try
{
EmptyWorkingSet(process.Handle);
}
catch (Exception)
{
...
}
}
}
It seems to be working fine, I was able to bring down memory usage of some programs like explorer from 100,000 Kb down to 2,000 Kb. That's pretty good but is there a side effect on doing this? Some commercial software are also using this like Yamicsoft Vista/Xp manager and Firefox Optimizer to name a few so i'm thinking if this has no bad side effects or is there?