Pale Musings

Thoughts from a mind twisted by tech and sports

Troubleshooting Memory Leaks in .NET

OK, you’re still here.  You are a brave soul if you’ve stuck around after a title like that, or else you are desperate!  That is exactly where I found myself over the last two days.

A product we are currently working on has a process that, well, processes a lot.  It goes through several different data gathering, manipulation, saving and printing operations.  The end result of this process is a print job that takes about an hour and produces about 1000 printed pages.

For the development we normally sent the jobs to a PDF printer or simply had it stop after printing 20 or 30 pages.  Finally the time came to give this a real test, a complete dry run!

*poof*

I know what you’re thinking, “you should have done that in Dev at least once!”  You are right of course, however sometimes we let things slip due to schedules and pressure.  Lesson learned, I hope!

It appeared as though there was a memory leak causing the application to crash.  Monitoring the memory usage with Process Explorer confirmed this to be the case.  Now to the task of tracking it down.

I must admit that I have never had a leak like this one.  After some initial code reviews there were a few places where we were able to determine the potential for problems.   Implementing code to fix these “phantom menaces” were not successful.  Now it was time to really dig in.  The downside was, I did not know how to dig, and I didn’t have a shovel. :(

After some searching around on Google, I ran across Finding .NET Memory Leaks by Phil Write.  It was not the easiest thing to find, but it was well worth the time.  Phil goes step by step through using sos.exe (Son of Strike) debugging extensions.   He explained the basis of how to track down what you think the problem is.  Unfortunately the problem was not that easy to find.  I ended up doing comparisons of the output of !dumpheap -stat from very early in the process and another dump from much later on down the line.  It was a tedious exercise, but a necessary one.  Finally I happened upon an object that had a large jump in it’s count between the two samples.  Now I had a place to start!  Using Phil’s instructions again I was able to find out what was holding on to a reference and implement a fix.  It also lead me to a second leak that we did not know existed and had been around for quite a while.  It turned out that the first leak that we fixed would not have been a problem if the other one had been behaving properly.

This is a good example of why bugs can be good.  The second memory leak will be taken care of within the next day or two and the product will be that much better for it.

Success!

Thanks Phil for such a wonderful and simple to understand article!

EDIT: 8/18/2010 – updated link to Phil’s article.  Thanks Aaron D for pointing it out!

March 2, 2007 Posted by palehorse | .NET, C#, Development, VB.NET | 4 Comments

Bill Gates Is Sending Me 1 Million Dollars

OK, that’s not true, but this post sounds like one of those spam chain emails that we have all seen. I finished reading this article from Greg’s Cool [Insert Clever Name] of The Day and decided to do a little more research on the matter. After reading through the material at the i’m Initiative Home Page I realized that maybe, just maybe somethings that sound too good to be true are really true! Microsoft is sharing a portion of the proceeds from the advertising with the charity of your choosing from their list. Now when I use IM, i’m making a difference for the Boy’s and Girl’s Club of America.

I will admit that I have been reluctant to upgrade to Windows Live Messenger, I just do not like the advertisements. Now, I don’t mind them because I know that my conversations are helping. All I need to do is use Live Messenger 8.1 and put a special tag at the end of my name ‘im Making a Difference, so that I still show up alphabetically (Greg’s tip), and it works.
The current charities that are being donated to and the codes you need to put at the end of your name are:

Text Code Cause
*red+u American Red Cross
*bgca Boys & Girls Club
*naf National AIDS Fund
*mssoc National Multiple Sclerosis Society
*9mil ninemillion.org
*sierra Sierra Club
*help StopGlobalWarming.org
*komen Susan G. Komen for the Cure
*unicef The US fund for UNICEF

If you support any of these charities and you are an MSN or Live Messenger user, I urge you to participate. Thanks Greg for sharing this one!

[Update] I see that this has become a popular topic today. This is an encouraging sign for these charities!

[Update 2] Now I wish I would have upgraded to Live Messenger earlier!  My old MSN Messenger had the odd problem of “lag”.  Any time a new conversation window would open, regardless of whether it was me double clicking on a name or someone else sending me an IM to start a conversation, Messenger would lag up to 30 seconds.  The window would show up, but I would not be able to type, nor would I see the sent message until the “lag” period had elapsed.

My problems have disappeared!  8.1 seems to be much more responsive.  I still do not know why it was behaving the way it was (my previous version was 7.<something>) but that’s all in the past now!  Not only are my conversations contributing to a fine charity, it’s doing it without the dreaded lag!

March 2, 2007 Posted by palehorse | Blogging, Reviews, Society / Politics | Leave a Comment

My First Foray Into Podcasting

DDOcast, the weekly podcast about Dungeons and Dragons Online: StormreachWell, sort of. This week I have been producing a 5+ minute segment for the weekly podcast called DDOCast. It is produced by Jerry Snook with content related to the Massively Muliplayer Online Role Playing Game (MMORPG) Dungeons and Dragons Online, or DDO. My segment, termed Tips with Marek, is a short bit in which I share various tips and tricks that I’ve learned in the past year of playing this excellent game.

It has taken a bit more effort than I originally though that it would. Creating the script was the lion’s share of the time as I would re-edit content until I felt it would sound good. The recording and editing of the sound file itself was not bad, that took only about 20 minutes. I’m sure that I will become more efficient with future segments. I also believe that my writing on this blog helped me with the script. I do not know if I was faster, but I believe the content was better.

If you are an online gamer at all, you should check out the DDO Cast or simply subscribe here. Jerry does a great job producing an entertaining and informative show. If you are just interested in my segment, I believe it will be in episode 5 which will probably be published around March 3rd.

[Update] I just finished listening to this weeks cast. My segment is in there, entitled Tips with Marek. It is in Episode 5 (3-3-07) available on Cyberears. Please feel free to leave comments here about my segment, or send email to marekthemage at gmail dot com. If you would like the transcript you may download Tips with Marek – Pulling MOB’s.

March 2, 2007 Posted by palehorse | Blogging, Dungeon's and Dragons Online, Games, Internet | Leave a Comment