GDI+ Article Now Available

March 28th, 2005

A GDI+ article that I wrote showing how to create a dynamic report based on the contents of a data grid is now available in the April 2005 issue of Visual Studio Magazine.

(Or see it online.)

6 Responses to “GDI+ Article Now Available”

  1. At

    We once had a discussion concerning the necessity of calling Dispose(). You referenced a source that said it was required; however, that source, as I recall, was VB City. :)
    My current understanding of Dispose() is that it provides a way for the user of the object to free unmanaged resources, but if the user does not explicitly call Dispose(), then the finalizer (destructor) will free the resources.

    See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconImplementingDisposeMethod.asp

    Congratulations on getting published!

  2. At

    Using Reflector, we can see the code for Pen.Dispose() is

    public void Dispose()
    {
    this.Dispose(true);
    GC.SuppressFinalize(this);
    }

    It calls Dispose(true), which actually does the clean up, and then tells the garbage collector not to call the finalizer for this object since its resources have already been freed.

    The finalizer for Pen is

    ~Pen()
    {
    this.Dispose(false);
    }

    So if you create a Pen object and don’t call Dispose(), the finalizer will call Dispose() for you when the object is garbage collected.

  3. At

    While the GC will eventually clean those up, eventually is the key word.

    And GDI resources can be expensive, especially in a long running application.

    See this article by Eric Gunnerson (former C# program manger at MS) for more information.

  4. At

    Lee,

    The article was very interesting. However, when I tried to use it (since I am a student studying C#) I found that oTable was not defined and therefore I got an error. I would appreciate the correction for this.

    Thank you,

    Al

  5. At

    Is this the very same Lee Falin that worked at CC!??

  6. At

    Very cool. I will have to grab a copy of that issue and read that article. Congrats.

    On the garbage collection stuff, the IDisposable pattern is meant to combat the fact that clean up in the .NET Framework is non-deterministic. A class implements IDisposable in order to make the clean up of unmanaged resources deterministic. The reason the the Dispose method calls SupressFinalize is because the Finalize call is one of the most expensive operations in the runtime, and since it is only used to clean up unmanaged resources, there is no need to call it if the user has already called Dispose.

    Just my two cents. :)

Leave a Reply