System.Drawing and Dispose()

I was playing around a bit with some owner drawn controls in winforms a little while ago (in preparation for the winforms exam, and just to see what it was all about). I was pleased to see that owner drawing was not that hard, however I did notice that there are lots of classes in the System.Drawing namespace that need to be disposed to free up the underlying system resources. That is fine, I have no problem calling dispose every now and then, however I came across this weblog entry a couple of days ago that scared me a little http://www.jelovic.com/weblog/e119.htm . Apparently some methods return newly created objects which need to be disposed when you’re finished using them, and others return a reference to an already existing object (that would probably be bad if you disposed). Looking at the example presented in Dejan Jelovic’s weblog I noticed that the MenuFont property of the SystemInformation class (that returns a new Font when the property is accessed) is static, in which case I probably would expect it to return a new instance, however so is the System.Drawing.Brushes.White call (which returns a reference to a white brush), so the behavior is inconsistent. Both are static methods and one returns a new instance while the other doesn’t. I will probably have to go thru my code and check.

In other news my templating code generator m3rlin has passed the 1000 download mark. I haven’t heard any bug reports or anything like that back from anyone. My wife swears she has only downloaded it a couple of hundred times ;). Also I am in the process of adding syntax hilighting to my xpath expression tester. It’s not done yet, but if there are any “advanced” xpath users with funky expressions they woulk like to try and break my parser with then leave a comment and I will get in touch. I’m also going to add namespace support.