The Jeff

The thoughts, concerns and major upheavals of Jeff Berg

November 2003 - Posts

Do More With Less
I love the new MS slogan (well kinda new), but I know if some other companies tried to push this to their staff it probably would look a lot like this:
Services, Memory & the big head

Overhead that is...

Well I have working on a small little project in my spare time that needed a Windows Service. So I made one. Wooopideee doo, how easy the .Net Framework makes life. Well after I get it running and all I see that my very small Windows Service is taking up 15 MB of RAM!!!. WHAT??? No way... So I go ahead and remove all of the references to my code and recompiled. 12MB...well that seems a bit large for nothing. So I did some research, durring this research I found a really good search engine to find things .net related right here. (shhh it's our little secret). All in all I found out that I am not familiar with the inner workings of .net (YET!!!), so I am glad there are so people could answer my question and this little ladies question with this code:

public class MemoryManagement
{
      private MemoryManagement() {}

      [System.Runtime.InteropServices.DllImport ("kernel32.dll")]
      private extern static int SetProcessWorkingSetSize (IntPtr hProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);

      public static void SwapOutProcess() 
      {
     
GC.Collect();
     
GC.WaitForPendingFinalizers();
     
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
           
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
      }
}

Yahoo, this cut down my service in half. Now it is 7-8MB. I will see how large it is in the morning. Hope my pain could help someone else.

Oh and 7MB still isn't preferable, anyone know of a way to cut it down more?

More Posts