August 2006 - Posts

Ian Griffiths: "You can't just leave everything to the GC"

In another follow-up to the thread I mentioned in my previous post, Ian Griffiths talks about some common misunderstandings about how .NET’s Garbage Collector works and how you interact with it via IDisposable.  In this reply he also mentions:

The two widely believed GC falsehoods: "I don't have to free stuff - the GC does it for me" and "The GC calls Dispose" - are two of the biggest barriers to understanding and working effectively with non-memory resources.

Posted by PSteele | with no comments

Handing out Disposable objects

Vince asks a question about handing out Disposable objects:

Lets say I have a class that has a method that returns a new DataSet:

public DataSet GetData();

I'll have no control over the DataSet being disposed.  As an object creator
is it my concern that the object I created eventually gets disposed or
should I not care and trust that the consumer of this method will do the
right thing?

A good thread to read.  I especially liked Frans’ response:

When you buy a happy meal at McDonalds, you're responsible for disposing the left overs and the rest of the trash, not Donald (sic) McD. 

Posted by PSteele | 1 comment(s)

OpenFileDialog and the current directory

Just found out something odd that I never noticed before.  If you use the OpenFileDialog class to allow a user to select a file, then once they’ve selected a file, the directory that file is in is now your application’s current directory!  Huh?  Seems odd to me.

There’s an easy workaround.  The OpenFileDialog class has a RestoreDirectory property (actually, it comes from the base class FileDialog) which you can set to true to disable this quirky behavior.  Why it defaults to false is something I can’t answer…

Posted by PSteele | 1 comment(s)
More Posts