Skip to content

Remove session finalizer #2811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions src/NHibernate/Impl/SessionImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,14 +1483,6 @@ public void Reconnect(DbConnection conn)
private string fetchProfile;
private IDisposable _context;

/// <summary>
/// Finalizer that ensures the object is correctly disposed of.
/// </summary>
~SessionImpl()
{
Dispose(false);
}

/// <summary>
/// Perform a soft (distributed transaction aware) close of the session
/// </summary>
Expand All @@ -1517,15 +1509,12 @@ public void Dispose()
_context?.Dispose();
}

//TODO: Get rid of isDisposing parameter. Finalizer is removed as not needed, so isDisposing is always true
/// <summary>
/// Takes care of freeing the managed and unmanaged resources that
/// this class is responsible for.
/// </summary>
/// <param name="isDisposing">Indicates if this Session is being Disposed of or Finalized.</param>
/// <remarks>
/// If this Session is being Finalized (<c>isDisposing==false</c>) then make sure not
/// to call any methods that could potentially bring this Session back to life.
/// </remarks>
private void Dispose(bool isDisposing)
{
using (BeginContext())
Expand All @@ -1546,8 +1535,6 @@ private void Dispose(bool isDisposing)
{
Close();
}
// nothing for Finalizer to do - so tell the GC to ignore it
GC.SuppressFinalize(this);
}

// free unmanaged resources here
Expand Down
12 changes: 1 addition & 11 deletions src/NHibernate/Impl/StatelessSessionImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -759,14 +759,6 @@ public IQueryOver<T, T> QueryOver<T>(Expression<Func<T>> alias) where T : class
private bool _isAlreadyDisposed;
private IDisposable _context;

/// <summary>
/// Finalizer that ensures the object is correctly disposed of.
/// </summary>
~StatelessSessionImpl()
{
Dispose(false);
}

///<summary>
///Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///</summary>
Expand All @@ -793,6 +785,7 @@ public void Dispose()
}
}

//TODO: Get rid of isDisposing parameter. Finalizer is removed as not needed, so isDisposing is always true
protected void Dispose(bool isDisposing)
{
using (BeginContext())
Expand All @@ -811,9 +804,6 @@ protected void Dispose(bool isDisposing)
{
Close();
}

// nothing for Finalizer to do - so tell the GC to ignore it
GC.SuppressFinalize(this);
}

// free unmanaged resources here
Expand Down