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.
A recent issue of MSDN magazine had a couple of interesting articles. Check out this one:
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:
This is a Q&A, and the Q is:
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:
This sounds like it wouldn’t have anything to do with memory, but here’s the first paragraph:
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.
Okay, back to debugging some C++. Oleosaurus out.