dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]lesson in dispose


From: Rhys Weatherley
Subject: Re: [DotGNU]lesson in dispose
Date: Sun, 16 Nov 2003 08:15:33 +1000
User-agent: KMail/1.4.3

On Sunday 16 November 2003 05:32 am, Neil Cawse wrote:

> Is this correct?

David's answer was pretty good.  I'll only add a few things.

The standard dispose setup is like this:

    ~Foo()
    {
        Dispose(false);
    }

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

    protected virtual void Dispose(bool disposing)
    {
        // do the actual dispose work
    }

You should always call "Dispose(bool)" from both the finalizer and the 
Dispose() method, even if there are no unmanaged resources in play.  I 
usually also ignore the "disposing" flag completely and do the same kind of 
dispose regardless in "Dispose(bool)".

Because 99% of our system is fully managed, the distinction that "disposing" 
implies is unimportant, and so it is safer to treat both cases the same to 
emulate MS which will expect the finalizer to do a full dispose in most cases 
of interest.

Cheers,

Rhys.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]