Archive: March 11, 2008

<<< March 10, 2008

Home

March 12, 2008 >>>


Oleosaurus: the dispose pattern

Tuesday,  03/11/08  10:03 PM

You all know how much I love .NET.  And you all pretty much figure I’m a hopeless dinosaur, and I just don’t get it.  And you’re all pretty tired of hearing me rant about it.  So, sorry…  but yes, here’s another one.  You may click "back" and get on with your life as appropriate.

<rant>

A recent issue of MSDN magazine had a couple of interesting articles.  Check out this one:

CLR Inside Out: managing Object Lifetime

So we all know, one of the key benefits of .NET is that the CLR performs garbage collection.  This is probably the most-often cited advantage of C# over C++.  (And for that matter, of Java over C++.)  Yet here we have an entire article describing something called “the Dispose pattern”, as a way to subvert the CLR’s garbage collection!  

The Dispose pattern is a really cool thing – in any object you can implement the IDisposable interface, and then you can call a Dispose method to free the object’s storage.  Wow!  This is an excellent solution to the pesky problems of garbage collection, wherein you have no control over when dead objects’ storage is released, and you have the storage deletion done in another thread, and you have potential and unpredictable hangs while the garbage collection takes place.  You just call Dispose, and poof, the object frees its memory.  How great is that?

Back in the old days of C++, we had a similar pattern.  We called it delete.  But I digress.

Then we have this article:

.NET matters: debugging finalizers

This is a Q&A, and the Q is:

I have a bunch of custom types that, for one reason or another, need to implement IDisposable. I want to make sure that the other developers on my team using this class always dispose of my types correctly. What can I do to warn one of my teammates if he forgets to call Dispose?

I can’t quote the A because it is about ten pages long.  The gist of it is that there’s a bunch of caveats you have to worry about if you implement “the Dispose pattern”.  You can cause deadlocks, end up with memory leaks, have difficulty debugging destructors, all kinds of fun stuff.  All the fun stuff that never happens because you have a garbage collector.  Yeah.  See the problem with the Dispose pattern is you have to remember to call Dispose.

Back in the old days of C++, we had a similar problem with delete.  You had to remember to use it.  But I digress.

And finally we have this article:

Bugslayer: Measuring the Impact of View State

This sounds like it wouldn’t have anything to do with memory, but here’s the first paragraph:

Isn't it funny how the Microsoft .NET Framework is thought of as an environment where you don't have to think about memory? Of course, what's one of the number one issues that continues to plague managed applications today? Memory! Why? When the garbage collector runs to reclaim memory, the common language runtime (CLR) suspends all the threads in the application—and no work gets done. When you're not getting any work done, you have a performance problem.

It is really funny that the .NET framework is though of as an environment where you don’t have to think about memory.  Hilarious, in fact.

</rant>

Okay, back to debugging some C++.  Oleosaurus out.

 

 

Tuesday,  03/11/08  10:46 PM

Busier than a cat in a sandbox over here, and curiously not much happening out there...  (I refuse to comment on the sexual travails of a certain [soon to be ex-] governor.)

Bram Cohen (creator of Bittorrent) usually blogs about esoteric technology, but occasionally considers other things also: Now is the time when the US media starts to lie.  "It happens every time - just when it's becoming clear who's going to get the nomination, the media completely manufactures the story of a competitive race, because it sells newspapers.  The truth is, it's basically over. The chances of Clinton winning the Democratic nomination have become remote. Now that that's the case, I feel it's time to talk about how completely surreal her campaign has been."  Great points, actually. 

Mitt Romney is now running for Vice President.  Seems like a decent choice, actually.  He is a successful businessman and Governor, and complements McCain.  Whether they get along and could work together is another matter.

Amazing: IBM builds Virtual Healthcare Island.  "The IBM Virtual Healthcare Island is designed with a futuristic atmosphere and provides visitors with an interactive demonstration of IBM's open-standards-based Health Information Exchange (HIE) architecture. Working with project leads in the U.S., the island was designed and built by an all-IBM-India team."  It does not appear to incorporate digital pathology, strangely, which I am trying to change :) 

This is so excellent: The writing's in the walls.  When I was at Caltech, one of the joys of the undergraduate dorms was the incredible murals painted on the walls by those procrastinating from studying...  these dorms have been refurbished and the walls have been painted over, but the memory of the murals is now preserved online. 

I've begun re-reading Andrew Parker's excellent In the Blink of an Eye.  This is a book of ideas, and the ideas are really amazing.  The central theory is that the Cambrian explosion of variation among species was triggered by the evolutionary "discovery" of eyes; predators had a new weapon, and prey a new defense, and an incredible evolutionary arms race was the result.  It rings true - there is plenty of evidence, carefully presented - and I recommend this book to anyone who is thoughtful about such things... 

 
 

Return to the archive.