Ive been using EmptyWorkingSet to free up memory in a new tool, but is this really a good/safe way of dong it (I edited slighty for all process's). Code: [DllImport("psapi.dll")] // public static extern bool EmptyWorkingSet(IntPtr hProcess); static extern int EmptyWorkingSet(IntPtr hwProc); public void FreeMem() { try { // EmptyWorkingSet(Process.GetCurrentProcess().Handle); // get handle to process's foreach (Process process in Process.GetProcesses()) { try { // empty as much as possible of working set EmptyWorkingSet(process.Handle); } catch { //... } } } catch (Exception Error) { MessageBox.Show(Error.Message); } } Usage = FreeMem() Original source: http://stackoverflow.com/questions/1812018/what-are-the-side-effects-of-using-emptyworkingset Any feedback ?
It slowdown the system, because the enviroment clean all stream called functions in the memory, isn't recommended the use of this function on all system or in a single process, can cause errors, hangs or bugs on the cleaned process.
Thanks Josh, im a little confused with this as it does free up my system according to my function for available Ram usage ? Edit, maybe i can redirect it to my current working process to free up.. ?
The use of EmptyWorkingSet function will "clean" the Process by handle, it will apparently UP the free memory, but can cause errors in the optimized process, certainly this applications will reload the memory with the use, here's the slowdown in the applications use. If you need of an large memory, I advise the use of this function on all processes, less your application, "slowdown" the system, but will make free megabytes on the memory.
Thanks again Josh.. However it still is working ok for me here, my system is responding to every call i make for it..
I've some experiences with the psapi.dll, it's present since Windows XP, some applications that clean the memory use this library. I see problems with this function using my Athlon 1.8GHz with 128MB of RAM
Thanks Josh, well i think it best to add a warning for users that want to use this function in my tool..