"Fortunate are those who take the first steps.” ― Paulo Coelho

Now you can Trim your .NET Application Memory easily.

Memory Trimmer

Memory Trimmer

As a part of Development using WPF,  we get complaints as ‘Memory consumption keeps increasing on time and never comes down’ and noises on Memory leakage. Ofcourse there are some loose ends in WPF design which takes developer for a ride. When we do a close analysis with tools like RedGate, we can spot those mysterious spot if we are lucky, but not always.

Back to our problem -At some point, they are forced to kill the application or Hang. Initially we don’t know because of  code or memory leakage for the root cause. The reason could be of anything and need closer investigation in both sides.

Just imagine you don’t find wrong from the developer/code side, but still you see the memory keeps up shooting up….Here is what you have to do, but not mandate to have such code always unless your ‘App’ require special trimming.

I wrote a tool (started as a POC) called Memory Trimmer, which actually has the below line,

SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);

Original inspiration for this tool (MemoryTrimmer) was from this blog.

Here is the sample uploaded and shared in my Skydrive.

Pls download and leave your comment/review points if you find any.

Happy Coding !!

I wrote a mail to MS (Carol Buchmiller,Senior Programming Writer, Windows Server UA) and here is the Q & A’s

Q: I’m confused of using ‘-1’ for both SetProcessWorkingSetSize(t1process.Handle, -1, -1);
Will it hurt the OS or Application performance if I set these values explicitly with -1 ?

Carol B -Answer : It depends on your application. The values (-1, -1) tell the memory manager to keep the working set as small as possible, so
the memory footprint of your application would be small. However, if your application is accessing a lot of data in memory, these values might
trigger more page faults, which causes the memory manager to have to load the page from disk. This would definitely affect the performance.

The best recommendation is to try it and see what effect it has on the performance of your application.

Thanks Carol B for the reply.


September 1, 2011 - Posted by | Uncategorized

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: