Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10119/NHibernate/Impl
Modified Files:
EnumerableImpl.cs
Log Message:
implemented standard IDisposable pattern.
Index: EnumerableImpl.cs
===================================================================
RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/EnumerableImpl.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** EnumerableImpl.cs 16 Jan 2005 19:55:42 -0000 1.9
--- EnumerableImpl.cs 5 Apr 2005 14:24:34 -0000 1.10
***************
*** 152,157 ****
/// <summary>
! /// Releases resources that the EnumerableImpl acquired.
/// </summary>
/// <remarks>
/// The command is closed and the reader is disposed. This allows other ADO.NET
--- 152,182 ----
/// <summary>
! /// A flag to indicate if <c>Disose()</c> has been called.
! /// </summary>
! private bool _isAlreadyDisposed;
!
! /// <summary>
! /// Finalizer that ensures the object is correctly disposed of.
/// </summary>
+ ~EnumerableImpl()
+ {
+ Dispose( false );
+ }
+
+ /// <summary>
+ /// Takes care of freeing the managed and unmanaged resources that
+ /// this class is responsible for.
+ /// </summary>
+ public void Dispose()
+ {
+ log.Debug( "running EnumerableImpl.Dispose()" );
+ Dispose( true );
+ }
+
+ /// <summary>
+ /// Takes care of freeing the managed and unmanaged resources that
+ /// this class is responsible for.
+ /// </summary>
+ /// <param name="isDisposing">Indicates if this EnumerableImpl is being Disposed of or Finalized.</param>
/// <remarks>
/// The command is closed and the reader is disposed. This allows other ADO.NET
***************
*** 159,172 ****
/// EnumerableImpl.
/// </remarks>
! public void Dispose()
{
! log.Debug( "disposing of enumerator" );
! // if there is still a possibility of moving next then we need to clean up
! // the resources - otherwise the cleanup has already been done.
! if( _hasNext )
{
! _currentResults = null;
! _sess.Batcher.CloseQueryCommand( _cmd, _reader );
}
}
--- 184,214 ----
/// EnumerableImpl.
/// </remarks>
! protected virtual void Dispose(bool isDisposing)
{
! if( _isAlreadyDisposed )
{
! // don't dispose of multiple times.
! return;
}
+
+ // free managed resources that are being managed by the EnumerableImpl if we
+ // know this call came through Dispose()
+ if( isDisposing )
+ {
+ // if there is still a possibility of moving next then we need to clean up
+ // the resources - otherwise the cleanup has already been done by the
+ // PostMoveNext method.
+ if( _hasNext )
+ {
+ _currentResults = null;
+ _sess.Batcher.CloseQueryCommand( _cmd, _reader );
+ }
+ }
+
+ // free unmanaged resources here
+
+ _isAlreadyDisposed = true;
+ // nothing for Finalizer to do - so tell the GC to ignore it
+ GC.SuppressFinalize( this );
}
|