diff --git a/ortools/sat/csharp/CpSolver.cs b/ortools/sat/csharp/CpSolver.cs
index c2a1449ee0..9a5a89dc42 100644
--- a/ortools/sat/csharp/CpSolver.cs
+++ b/ortools/sat/csharp/CpSolver.cs
@@ -26,7 +26,7 @@ namespace Google.OrTools.Sat
* variables in the best solution, as well as general statistics of the search.
*
*/
-public sealed class CpSolver : IDisposable
+public class CpSolver : IDisposable
{
private LogCallback? _log_callback;
private BestBoundCallback? _best_bound_callback;
@@ -207,19 +207,36 @@ public sealed class CpSolver : IDisposable
public string SolutionInfo() => Response!.SolutionInfo;
- public void Dispose()
+ ///
+ /// Releases unmanaged resources and optionally releases managed resources.
+ ///
+ /// true to release both managed and unmanaged resources; false to release only unmanaged resources.
+ protected virtual void Dispose(bool disposing)
{
if (_disposed)
{
return;
}
- _best_bound_callback?.Dispose();
- _log_callback?.Dispose();
- ReleaseSolveWrapper();
+ if (disposing)
+ {
+ _best_bound_callback?.Dispose();
+ _log_callback?.Dispose();
+ ReleaseSolveWrapper();
+ }
+
_disposed = true;
}
+ ///
+ /// Releases all resources used by the CpSolver.
+ ///
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
[MethodImpl(MethodImplOptions.Synchronized)]
private void CreateSolveWrapper()
{
@@ -253,4 +270,4 @@ class BestBoundCallbackDelegate : BestBoundCallback
public override void NewBestBound(double bound) => _delegate(bound);
}
-} // namespace Google.OrTools.Sat
+} // namespace Google.OrTools.Sat
\ No newline at end of file