From f7b1469462f4ec28257c34aea158bc243b31fe2c Mon Sep 17 00:00:00 2001 From: Nikolaj Bjorner Date: Sat, 27 Feb 2021 11:02:58 -0800 Subject: [PATCH] Try freeing context in dispose method and not wait for finalizer #5043 --- src/api/dotnet/Context.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/api/dotnet/Context.cs b/src/api/dotnet/Context.cs index 8c1f8eb0e..b4afabe0e 100644 --- a/src/api/dotnet/Context.cs +++ b/src/api/dotnet/Context.cs @@ -4808,16 +4808,6 @@ namespace Microsoft.Z3 { // Console.WriteLine("Context Finalizer from " + System.Threading.Thread.CurrentThread.ManagedThreadId); Dispose(); - - if (refCount == 0 && m_ctx != IntPtr.Zero) - { - m_n_err_handler = null; - IntPtr ctx = m_ctx; - m_ctx = IntPtr.Zero; - Native.Z3_del_context(ctx); - } - else - GC.ReRegisterForFinalize(this); } /// @@ -4847,6 +4837,15 @@ namespace Microsoft.Z3 m_intSort = null; m_realSort = null; m_stringSort = null; + if (refCount == 0 && m_ctx != IntPtr.Zero) + { + m_n_err_handler = null; + IntPtr ctx = m_ctx; + m_ctx = IntPtr.Zero; + Native.Z3_del_context(ctx); + } + else + GC.ReRegisterForFinalize(this); } #endregion }