lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [19/38] lucenenet git commit: API: Lucene.Net.Search.ReferenceManager: Implemented proper dispose pattern.
Date Thu, 22 Jun 2017 05:25:20 GMT
API: Lucene.Net.Search.ReferenceManager: Implemented proper dispose pattern.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/8d6fb691
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/8d6fb691
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/8d6fb691

Branch: refs/heads/master
Commit: 8d6fb69158d1f31f58e7fdd6ad1b9b925b6554ce
Parents: 56025d3
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sat Jun 17 15:30:45 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sat Jun 17 15:37:29 2017 +0700

----------------------------------------------------------------------
 .../Search/TestSearcherManager.cs                |  2 +-
 src/Lucene.Net/Search/ReferenceManager.cs        | 19 ++++++++++---------
 2 files changed, 11 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8d6fb691/src/Lucene.Net.Tests/Search/TestSearcherManager.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Search/TestSearcherManager.cs b/src/Lucene.Net.Tests/Search/TestSearcherManager.cs
index 243e421..550adb8 100644
--- a/src/Lucene.Net.Tests/Search/TestSearcherManager.cs
+++ b/src/Lucene.Net.Tests/Search/TestSearcherManager.cs
@@ -431,7 +431,7 @@ namespace Lucene.Net.Search
         {
             // test that we can close SM twice (per IDisposable's contract).
             Directory dir = NewDirectory();
-            (new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null))).Dispose();
+            using (var iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT,
null))) { }
             SearcherManager sm = new SearcherManager(dir, null);
             sm.Dispose();
             sm.Dispose();

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8d6fb691/src/Lucene.Net/Search/ReferenceManager.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Search/ReferenceManager.cs b/src/Lucene.Net/Search/ReferenceManager.cs
index 8cc4174..0d58f11 100644
--- a/src/Lucene.Net/Search/ReferenceManager.cs
+++ b/src/Lucene.Net/Search/ReferenceManager.cs
@@ -159,14 +159,8 @@ namespace Lucene.Net.Search
         {
             lock (this)
             {
-                if (current != null)
-                {
-                    // make sure we can call this more than once
-                    // closeable javadoc says:
-                    // if this is already closed then invoking this method has no effect.
-                    SwapReference(null);
-                    AfterClose();
-                }
+                Dispose(true);
+                GC.SuppressFinalize(this);
             }
         }
 
@@ -179,8 +173,15 @@ namespace Lucene.Net.Search
         /// Called after <see cref="Dispose()"/>, so subclass can free any resources.
</summary>
         /// <exception cref="System.IO.IOException"> if the after dispose operation
in a sub-class throws an <see cref="System.IO.IOException"/>
         /// </exception>
-        protected virtual void AfterClose() // LUCENENET TODO: API: Rename AfterDispose()
? Or perhaps just use dispose pattern.
+        protected virtual void Dispose(bool disposing)
         {
+            if (disposing && current != null)
+            {
+                // make sure we can call this more than once
+                // closeable javadoc says:
+                // if this is already closed then invoking this method has no effect.
+                SwapReference(null);
+            }
         }
 
         private void DoMaybeRefresh()


Mime
View raw message