activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jim Gomes (JIRA)" <j...@apache.org>
Subject [jira] Commented: (AMQNET-50) Disposable objects should follow standard disposable implementation pattern
Date Fri, 31 Aug 2007 17:06:24 GMT

    [ https://issues.apache.org/activemq/browse/AMQNET-50?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_40055
] 

Jim Gomes commented on AMQNET-50:
---------------------------------

Aaagh!  The formatting of the code snippet is all messed up.  Should have read the help on
how to format code.  Too bad I can't edit the original description.  Let's try formatting
this again:

{code:title=Disposable Pattern|borderStyle=solid}
class Disposable : public IDispose
{
    private bool disposed = false;

    ~Disposable()
    {
        Dispose(false);
    }

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

    protected void Dispose(bool disposing)
    {
        if(disposed)
        {
            return;
        }

        if(disposing)
        {
            // Dispose managed code here
        }

        // Dispose unmanaged code here

        disposed = true;
    }
}
{code}


> Disposable objects should follow standard disposable implementation pattern
> ---------------------------------------------------------------------------
>
>                 Key: AMQNET-50
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-50
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: ActiveMQ Client
>         Environment: Windows XP SP2, .NET 2.0
>            Reporter: Jim Gomes
>            Assignee: James Strachan
>            Priority: Minor
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> Objects that implement the IDispose interface and have unmanaged resources should use
the dispose pattern that uses an internal method to dispose of the objects and then turns
off the finalizer call from the garbage collector.  This allows for safe and efficient disposable
of unmanaged resources.
> The following objects implement the IDisposable interface and have attachments to unmanaged
resources.  
> ActiveMQ.Connection
> ActiveMQ.Session
> ActiveMQ.MessageProducer
> ActiveMQ.MessageConsumer
> The basic pattern is as follows:
> class Disposable : public IDispose
> {
>     private bool disposed = false;
>     ~Disposable()
>     {
>         Dispose(false);
>     }
>     public void Dispose()
>     {
>         Dispose(true);
>         GC.SuppressFinalize(this);
>     }
>     protected void Dispose(bool disposing)
>     {
>         if(disposed)
>         {
>             return;
>         }
>         if(disposing)
>         {
>             // Dispose managed code here
>         }
>         // Dispose unmanaged code here
>         disposed = true;
>     }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message