lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccurr...@apache.org
Subject [Lucene.Net] svn commit: r1290981 [1/2] - in /incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk: src/core/ src/core/Analysis/ src/core/Index/ src/core/Search/ src/core/Store/ src/core/Util/ src/core/Util/Cache/ test/core/ test/core/Analysis/ test/core/Index/ tes...
Date Sun, 19 Feb 2012 09:54:45 GMT
Author: ccurrens
Date: Sun Feb 19 09:54:42 2012
New Revision: 1290981

URL: http://svn.apache.org/viewvc?rev=1290981&view=rev
Log:
[LUCENENET-468] - Implemented dispose on all classes that had void Close
Fixed a few tests failing only in release

Modified:
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/NumericTokenStream.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/TeeSinkTokenFilter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/TokenStream.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/AbstractAllTermDocs.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/AllTermDocs.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/CompoundFileWriter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ConcurrentMergeScheduler.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/DirectoryReader.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/DocumentsWriter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FieldsReader.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FieldsWriter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FilterIndexReader.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsDocsWriter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsFieldsWriter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsPositionsWriter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsTermsWriter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexFileDeleter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexReader.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexWriter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogByteSizeMergePolicy.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogDocMergePolicy.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogMergePolicy.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MergePolicy.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MergeScheduler.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MultiLevelSkipListReader.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MultipleTermPositions.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ParallelReader.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ReusableStringReader.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMergeInfo.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMergeQueue.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMerger.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentReader.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermDocs.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermEnum.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermPositions.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SerialMergeScheduler.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/StoredFieldsWriter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermDocs.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermEnum.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermInfosReader.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermInfosWriter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermPositions.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermVectorsReader.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermVectorsWriter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Lucene.Net.csproj
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/FilteredTermEnum.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/FuzzyTermEnum.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/IndexSearcher.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/MultiSearcher.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/NumericRangeQuery.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/Searchable.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/Searcher.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/SimilarityDelegator.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Search/SingleTermEnum.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Store/BufferedIndexInput.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Store/BufferedIndexOutput.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Store/CheckSumIndexOutput.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Store/IndexOutput.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Store/RAMOutputStream.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Store/SimpleFSDirectory.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Util/Cache/Cache.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Util/Cache/SimpleMapCache.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Util/CloseableThreadLocal.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Analysis/TestCachingTokenFilter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/App.config
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Index/TestDocumentWriter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Index/TestFieldsReader.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Index/TestIndexWriter.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Index/TestPayloads.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Index/TestTermVectorsReader.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Index/TestTermdocPerf.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Lucene.Net.Test.csproj
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/QueryParser/TestMultiFieldQueryParser.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/JustCompileSearch.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/TestPositionIncrement.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Search/TestSort.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/Store/MockRAMOutputStream.cs
    incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/test/core/TestMergeSchedulerExternal.cs

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/NumericTokenStream.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/NumericTokenStream.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/NumericTokenStream.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/NumericTokenStream.cs Sun Feb 19 09:54:42 2012
@@ -84,7 +84,7 @@ namespace Lucene.Net.Analysis
 	/// might change in incompatible ways in the next release.</font>
 	///   Since 2.9
 	/// </summary>
-	public sealed class NumericTokenStream:TokenStream
+	public sealed class NumericTokenStream : TokenStream
 	{
 		private void  InitBlock()
 		{
@@ -209,6 +209,11 @@ namespace Lucene.Net.Analysis
 				throw new System.SystemException("call set???Value() before usage");
 			shift = 0;
 		}
+
+        protected override void Dispose(bool disposing)
+        {
+            // Do nothing.
+        }
 		
 		// @Override
 		public override bool IncrementToken()

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/TeeSinkTokenFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/TeeSinkTokenFilter.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/TeeSinkTokenFilter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/TeeSinkTokenFilter.cs Sun Feb 19 09:54:42 2012
@@ -188,13 +188,13 @@ namespace Lucene.Net.Analysis
 			}
 		}
 		
-		public sealed class SinkTokenStream:TokenStream
+		public sealed class SinkTokenStream : TokenStream
 		{
             private LinkedList<AttributeSource.State> cachedStates = new LinkedList<AttributeSource.State>();
 			private AttributeSource.State finalState;
 			private IEnumerator<AttributeSource.State> it = null;
 			private SinkFilter filter;
-			
+
 			internal SinkTokenStream(AttributeSource source, SinkFilter filter)
                 : base(source)
 			{
@@ -250,6 +250,11 @@ namespace Lucene.Net.Analysis
 			{
 				it = cachedStates.GetEnumerator();
 			}
+
+		    protected override void Dispose(bool disposing)
+		    {
+		        // Do nothing.
+		    }
 		}
 		
 		private static readonly SinkFilter ACCEPT_ALL_FILTER;

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/TokenStream.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/TokenStream.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/TokenStream.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Analysis/TokenStream.cs Sun Feb 19 09:54:42 2012
@@ -159,7 +159,6 @@ namespace Lucene.Net.Analysis
             Dispose(true);
         }
 
-	    protected virtual void Dispose(bool disposing)
-	    { }
+	    protected abstract void Dispose(bool disposing);
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/AbstractAllTermDocs.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/AbstractAllTermDocs.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/AbstractAllTermDocs.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/AbstractAllTermDocs.cs Sun Feb 19 09:54:42 2012
@@ -113,10 +113,7 @@ namespace Lucene.Net.Index
             Dispose(true);
         }
 
-        protected virtual void Dispose(bool disposing)
-        {
-            
-        }
+        protected abstract void Dispose(bool disposing);
 
         public abstract bool IsDeleted(int doc);
     }

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/AllTermDocs.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/AllTermDocs.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/AllTermDocs.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/AllTermDocs.cs Sun Feb 19 09:54:42 2012
@@ -34,6 +34,11 @@ namespace Lucene.Net.Index
 			}
 		}
 
+        protected override void Dispose(bool disposing)
+        {
+            // Do nothing.
+        }
+
         public override bool IsDeleted(int doc)
         {
             return deletedDocs != null && deletedDocs.Get(doc);

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/CompoundFileWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/CompoundFileWriter.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/CompoundFileWriter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/CompoundFileWriter.cs Sun Feb 19 09:54:42 2012
@@ -44,7 +44,7 @@ namespace Lucene.Net.Index
 	/// contains a long pointer to the start of this file's data section, and a String
 	/// with that file's name.
 	/// </summary>
-	public sealed class CompoundFileWriter
+	public sealed class CompoundFileWriter : IDisposable
 	{
 		
 		private sealed class FileEntry
@@ -131,92 +131,102 @@ namespace Lucene.Net.Index
 			entries.AddLast(entry);
 		}
 		
-		/// <summary>Merge files with the extensions added up to now.
-		/// All files with these extensions are combined sequentially into the
-		/// compound stream. After successful merge, the source files
-		/// are deleted.
-		/// </summary>
-		/// <throws>  IllegalStateException if close() had been called before or </throws>
-		/// <summary>   if no file has been added to this object
-		/// </summary>
+        [Obsolete("Use Dispose() instead")]
 		public void  Close()
 		{
-			if (merged)
-				throw new System.SystemException("Merge already performed");
-			
-			if ((entries.Count == 0))
-				throw new System.SystemException("No entries to merge have been defined");
-			
-			merged = true;
-			
-			// open the compound stream
-			IndexOutput os = null;
-			try
-			{
-				os = directory.CreateOutput(fileName);
-				
-				// Write the number of entries
-				os.WriteVInt(entries.Count);
-				
-				// Write the directory with all offsets at 0.
-				// Remember the positions of directory entries so that we can
-				// adjust the offsets later
-				long totalSize = 0;
-				foreach(FileEntry fe in entries)
-				{
-					fe.directoryOffset = os.GetFilePointer();
-					os.WriteLong(0); // for now
-					os.WriteString(fe.file);
-					totalSize += directory.FileLength(fe.file);
-				}
-				
-				// Pre-allocate size of file as optimization --
-				// this can potentially help IO performance as
-				// we write the file and also later during
-				// searching.  It also uncovers a disk-full
-				// situation earlier and hopefully without
-				// actually filling disk to 100%:
-				long finalLength = totalSize + os.GetFilePointer();
-				os.SetLength(finalLength);
-				
-				// Open the files and copy their data into the stream.
-				// Remember the locations of each file's data section.
-				byte[] buffer = new byte[16384];
-				foreach(FileEntry fe in entries)
-				{
-					fe.dataOffset = os.GetFilePointer();
-					CopyFile(fe, os, buffer);
-				}
-				
-				// Write the data offsets into the directory of the compound stream
-				foreach(FileEntry fe in entries)
-				{
-					os.Seek(fe.directoryOffset);
-					os.WriteLong(fe.dataOffset);
-				}
-				
-				System.Diagnostics.Debug.Assert(finalLength == os.Length());
-				
-				// Close the output stream. Set the os to null before trying to
-				// close so that if an exception occurs during the close, the
-				// finally clause below will not attempt to close the stream
-				// the second time.
-				IndexOutput tmp = os;
-				os = null;
-				tmp.Close();
-			}
-			finally
-			{
-				if (os != null)
-					try
-					{
-						os.Close();
-					}
-					catch (System.IO.IOException e)
-					{
-					}
-			}
+		    Dispose();
 		}
+
+        /// <summary>Merge files with the extensions added up to now.
+        /// All files with these extensions are combined sequentially into the
+        /// compound stream. After successful merge, the source files
+        /// are deleted.
+        /// </summary>
+        /// <throws>  IllegalStateException if close() had been called before or </throws>
+        /// <summary>   if no file has been added to this object
+        /// </summary>
+        public void Dispose()
+        {
+            // Extract into protected method if class ever becomes unsealed
+
+            // TODO: Dispose shouldn't throw exceptions!
+            if (merged)
+                throw new System.SystemException("Merge already performed");
+
+            if ((entries.Count == 0))
+                throw new System.SystemException("No entries to merge have been defined");
+
+            merged = true;
+
+            // open the compound stream
+            IndexOutput os = null;
+            try
+            {
+                os = directory.CreateOutput(fileName);
+
+                // Write the number of entries
+                os.WriteVInt(entries.Count);
+
+                // Write the directory with all offsets at 0.
+                // Remember the positions of directory entries so that we can
+                // adjust the offsets later
+                long totalSize = 0;
+                foreach (FileEntry fe in entries)
+                {
+                    fe.directoryOffset = os.GetFilePointer();
+                    os.WriteLong(0); // for now
+                    os.WriteString(fe.file);
+                    totalSize += directory.FileLength(fe.file);
+                }
+
+                // Pre-allocate size of file as optimization --
+                // this can potentially help IO performance as
+                // we write the file and also later during
+                // searching.  It also uncovers a disk-full
+                // situation earlier and hopefully without
+                // actually filling disk to 100%:
+                long finalLength = totalSize + os.GetFilePointer();
+                os.SetLength(finalLength);
+
+                // Open the files and copy their data into the stream.
+                // Remember the locations of each file's data section.
+                byte[] buffer = new byte[16384];
+                foreach (FileEntry fe in entries)
+                {
+                    fe.dataOffset = os.GetFilePointer();
+                    CopyFile(fe, os, buffer);
+                }
+
+                // Write the data offsets into the directory of the compound stream
+                foreach (FileEntry fe in entries)
+                {
+                    os.Seek(fe.directoryOffset);
+                    os.WriteLong(fe.dataOffset);
+                }
+
+                System.Diagnostics.Debug.Assert(finalLength == os.Length());
+
+                // Close the output stream. Set the os to null before trying to
+                // close so that if an exception occurs during the close, the
+                // finally clause below will not attempt to close the stream
+                // the second time.
+                IndexOutput tmp = os;
+                os = null;
+                tmp.Close();
+            }
+            finally
+            {
+                if (os != null)
+                    try
+                    {
+                        os.Close();
+                    }
+                    catch (System.IO.IOException e)
+                    {
+                    }
+            }
+        }
+
 		
 		/// <summary>Copy the contents of the file with specified extension into the
 		/// provided output stream. Use the provided buffer for moving data

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ConcurrentMergeScheduler.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ConcurrentMergeScheduler.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ConcurrentMergeScheduler.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ConcurrentMergeScheduler.cs Sun Feb 19 09:54:42 2012
@@ -137,10 +137,13 @@ namespace Lucene.Net.Index
 			}
 		}
 		
-		public override void  Close()
-		{
-			closed = true;
-		}
+        protected override void Dispose(bool disposing)
+        {
+            //if (disposing)
+            //{
+                closed = true;
+            //}
+        }
 		
 		public virtual void  Sync()
 		{

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/DirectoryReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/DirectoryReader.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/DirectoryReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/DirectoryReader.cs Sun Feb 19 09:54:42 2012
@@ -964,7 +964,7 @@ namespace Lucene.Net.Index
                 // Have the deleter remove any now unreferenced
                 // files due to this commit:
                 deleter.Checkpoint(segmentInfos, true);
-                deleter.Close();
+                deleter.Dispose();
 
                 maxIndexVersion = segmentInfos.GetVersion();
                 
@@ -1243,7 +1243,7 @@ namespace Lucene.Net.Index
                         queue.Add(smi);
                     // initialize queue
                     else
-                        smi.Close();
+                        smi.Dispose();
                 }
                 
                 if (t != null && queue.Size() > 0)
@@ -1262,7 +1262,7 @@ namespace Lucene.Net.Index
                     if (smi.Next())
                         queue.Add(smi);
                     else
-                        smi.Close(); // done with segment
+                        smi.Dispose(); // done with segment
                 }
                 
                 int numMatchingSegments = 0;
@@ -1301,14 +1301,12 @@ namespace Lucene.Net.Index
                 return docFreq;
             }
             
-            public override void  Close()
+            protected override void Dispose(bool disposing)
             {
-                Dispose();
-            }
-
-            public override void Dispose()
-            {
-                queue.Close();
+                if (disposing)
+                {
+                    queue.Dispose();
+                }
             }
         }
         
@@ -1503,10 +1501,18 @@ namespace Lucene.Net.Index
 
             public virtual void Dispose()
             {
-                for (int i = 0; i < readerTermDocs.Length; i++)
+                Dispose(true);
+            }
+
+            protected virtual void Dispose(bool disposing)
+            {
+                if (disposing)
                 {
-                    if (readerTermDocs[i] != null)
-                        readerTermDocs[i].Close();
+                    for (int i = 0; i < readerTermDocs.Length; i++)
+                    {
+                        if (readerTermDocs[i] != null)
+                            readerTermDocs[i].Close();
+                    }
                 }
             }
         }

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/DocumentsWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/DocumentsWriter.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/DocumentsWriter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/DocumentsWriter.cs Sun Feb 19 09:54:42 2012
@@ -100,7 +100,7 @@ namespace Lucene.Net.Index
 	/// or none") added to the index.
 	/// </summary>
 	
-	public sealed class DocumentsWriter
+	public sealed class DocumentsWriter : IDisposable
 	{
 		internal class AnonymousClassIndexingChain:IndexingChain
 		{
@@ -873,14 +873,15 @@ namespace Lucene.Net.Index
 			}
 		}
 		
-		internal void  Close()
-		{
-			lock (this)
-			{
-				closed = true;
-				System.Threading.Monitor.PulseAll(this);
-			}
-		}
+        public void Dispose()
+        {
+            // Move to protected method if class becomes unsealed
+            lock (this)
+            {
+                closed = true;
+                System.Threading.Monitor.PulseAll(this);
+            }
+        }
 		
 		internal void  InitSegmentName(bool onlyDocStore)
 		{

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FieldsReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FieldsReader.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FieldsReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FieldsReader.cs Sun Feb 19 09:54:42 2012
@@ -34,7 +34,7 @@ namespace Lucene.Net.Index
 	/// It uses &lt;segment&gt;.fdt and &lt;segment&gt;.fdx; files.
 	/// 
 	/// </summary>
-	public sealed class FieldsReader : System.ICloneable
+	public sealed class FieldsReader : ICloneable, IDisposable
 	{
 		private FieldInfos fieldInfos;
 		
@@ -159,7 +159,7 @@ namespace Lucene.Net.Index
 				// wait for a GC to do so.
 				if (!success)
 				{
-					Close();
+					Dispose();
 				}
 			}
 		}
@@ -178,33 +178,34 @@ namespace Lucene.Net.Index
 		/// 
 		/// </summary>
 		/// <throws>  IOException </throws>
-		public /*internal*/ void  Close()
-		{
-			if (!closed)
-			{
-				if (fieldsStream != null)
-				{
-					fieldsStream.Close();
-				}
-				if (isOriginal)
-				{
-					if (cloneableFieldsStream != null)
-					{
-						cloneableFieldsStream.Close();
-					}
-					if (cloneableIndexStream != null)
-					{
-						cloneableIndexStream.Close();
-					}
-				}
-				if (indexStream != null)
-				{
-					indexStream.Close();
-				}
-				fieldsStreamTL.Close();
-				closed = true;
-			}
-		}
+        public void Dispose()
+        {
+            // Move to protected method if class becomes unsealed
+            if (!closed)
+            {
+                if (fieldsStream != null)
+                {
+                    fieldsStream.Close();
+                }
+                if (isOriginal)
+                {
+                    if (cloneableFieldsStream != null)
+                    {
+                        cloneableFieldsStream.Close();
+                    }
+                    if (cloneableIndexStream != null)
+                    {
+                        cloneableIndexStream.Close();
+                    }
+                }
+                if (indexStream != null)
+                {
+                    indexStream.Close();
+                }
+                fieldsStreamTL.Close();
+                closed = true;
+            }
+        }
 		
 		public /*internal*/ int Size()
 		{

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FieldsWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FieldsWriter.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FieldsWriter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FieldsWriter.cs Sun Feb 19 09:54:42 2012
@@ -28,7 +28,7 @@ using RAMOutputStream = Lucene.Net.Store
 namespace Lucene.Net.Index
 {
 	
-	sealed class FieldsWriter
+	sealed class FieldsWriter : IDisposable
 	{
 		internal const byte FIELD_IS_TOKENIZED = (0x1);
 		internal const byte FIELD_IS_BINARY = (0x2);
@@ -75,7 +75,7 @@ namespace Lucene.Net.Index
 				{
 					try
 					{
-						Close();
+						Dispose();
 					}
 					catch (System.Exception t)
 					{
@@ -106,7 +106,7 @@ namespace Lucene.Net.Index
 				{
 					try
 					{
-						Close();
+						Dispose();
 					}
 					catch (System.IO.IOException ioe)
 					{
@@ -169,11 +169,11 @@ namespace Lucene.Net.Index
 			fieldsStream.Flush();
 		}
 		
-		internal void  Close()
+		public void Dispose()
 		{
+            // Move to protected method if class becomes unsealed
 			if (doClose)
 			{
-				
 				try
 				{
 					if (fieldsStream != null)
@@ -208,7 +208,7 @@ namespace Lucene.Net.Index
 					{
 						// Ignore so we throw only first IOException hit
 					}
-					throw ioe;
+					throw;
 				}
 				finally
 				{

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FilterIndexReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FilterIndexReader.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FilterIndexReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FilterIndexReader.cs Sun Feb 19 09:54:42 2012
@@ -74,13 +74,23 @@ namespace Lucene.Net.Index
 			{
 				return in_Renamed.SkipTo(i);
 			}
-			public virtual void  Close()
+
+			public void Close()
 			{
 				Dispose();
 			}
-            public virtual void Dispose()
+
+            public void Dispose()
+            {
+                Dispose(true);
+            }
+
+            protected virtual void Dispose(bool disposing)
             {
-                in_Renamed.Close();
+                if (disposing)
+                {
+                    in_Renamed.Close();
+                }
             }
 		}
 		
@@ -129,21 +139,23 @@ namespace Lucene.Net.Index
 			{
 				return in_Renamed.Next();
 			}
+
 			public override Term Term()
 			{
 				return in_Renamed.Term();
 			}
+
 			public override int DocFreq()
 			{
 				return in_Renamed.DocFreq();
 			}
-			public override void  Close()
-			{
-				Dispose();
-			}
-            public override void Dispose()
+
+            protected override void Dispose(bool disposing)
             {
-                in_Renamed.Close();
+                if (disposing)
+                {
+                    in_Renamed.Close();
+                }
             }
 		}
 		

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsDocsWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsDocsWriter.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsDocsWriter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsDocsWriter.cs Sun Feb 19 09:54:42 2012
@@ -24,7 +24,7 @@ namespace Lucene.Net.Index
     /// <summary>Consumes doc and freq, writing them using the current
     /// index file format 
     /// </summary>
-	sealed class FormatPostingsDocsWriter:FormatPostingsDocsConsumer
+	sealed class FormatPostingsDocsWriter : FormatPostingsDocsConsumer, IDisposable
 	{
 		
 		internal IndexOutput out_Renamed;
@@ -123,11 +123,12 @@ namespace Lucene.Net.Index
 			lastDocID = 0;
 			df = 0;
 		}
-		
-		internal void  Close()
-		{
-			out_Renamed.Close();
-			posWriter.Close();
-		}
+
+        public void Dispose()
+        {
+            // Move to protected method if class becomes unsealed
+            out_Renamed.Dispose();
+            posWriter.Dispose();
+        }
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsFieldsWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsFieldsWriter.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsFieldsWriter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsFieldsWriter.cs Sun Feb 19 09:54:42 2012
@@ -64,8 +64,8 @@ namespace Lucene.Net.Index
 		/// <summary>Called when we are done adding everything. </summary>
 		internal override void  Finish()
 		{
-			termsOut.Close();
-			termsWriter.Close();
+			termsOut.Dispose();
+			termsWriter.Dispose();
 		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsPositionsWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsPositionsWriter.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsPositionsWriter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsPositionsWriter.cs Sun Feb 19 09:54:42 2012
@@ -25,7 +25,6 @@ namespace Lucene.Net.Index
 	
 	sealed class FormatPostingsPositionsWriter:FormatPostingsPositionsConsumer
 	{
-		
 		internal FormatPostingsDocsWriter parent;
 		internal IndexOutput out_Renamed;
 		
@@ -92,10 +91,11 @@ namespace Lucene.Net.Index
 			lastPayloadLength = - 1;
 		}
 		
-		internal void  Close()
-		{
-			if (out_Renamed != null)
-				out_Renamed.Close();
-		}
+        public void Dispose()
+        {
+            // Move to protected method if class becomes unsealed
+            if (out_Renamed != null)
+                out_Renamed.Close();
+        }
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsTermsWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsTermsWriter.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsTermsWriter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/FormatPostingsTermsWriter.cs Sun Feb 19 09:54:42 2012
@@ -20,9 +20,8 @@ using System;
 namespace Lucene.Net.Index
 {
 	
-	sealed class FormatPostingsTermsWriter:FormatPostingsTermsConsumer
+	sealed class FormatPostingsTermsWriter : FormatPostingsTermsConsumer, IDisposable
 	{
-		
 		internal FormatPostingsFieldsWriter parent;
 		internal FormatPostingsDocsWriter docsWriter;
 		internal TermInfosWriter termsOut;
@@ -70,9 +69,9 @@ namespace Lucene.Net.Index
 		{
 		}
 		
-		internal void  Close()
-		{
-			docsWriter.Close();
-		}
+        public void Dispose()
+        {
+            docsWriter.Dispose();
+        }
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexFileDeleter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexFileDeleter.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexFileDeleter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexFileDeleter.cs Sun Feb 19 09:54:42 2012
@@ -60,7 +60,7 @@ namespace Lucene.Net.Index
     /// directly with no retry logic.</para>
     /// </summary>
 	
-	public sealed class IndexFileDeleter
+	public sealed class IndexFileDeleter : IDisposable
 	{
 		
 		//// Files that we tried to delete but failed (likely
@@ -381,8 +381,9 @@ namespace Lucene.Net.Index
 			Refresh(null);
 		}
 		
-		public void  Close()
+		public void Dispose()
 		{
+            // Move to protected method if class becomes unsealed
 			// DecRef old files from the last checkpoint, if any:
 			int size = lastFiles.Count;
 			if (size > 0)

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexReader.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexReader.cs Sun Feb 19 09:54:42 2012
@@ -1124,29 +1124,35 @@ namespace Lucene.Net.Index
 		/// <summary>Implements commit.</summary>
 	    protected internal abstract void DoCommit(System.Collections.Generic.IDictionary<string, string> commitUserData);
 
-		/// <summary> Closes files associated with this index.
-		/// Also saves any new deletions to disk.
-		/// No other methods should be called after this has been called.
-		/// </summary>
-		/// <throws>  IOException if there is a low-level IO error </throws>
-		public void  Close()
+        [Obsolete("Use Dispose() instead")]
+		public void Close()
 		{
-			lock (this)
-			{
-				if (!closed)
-				{
-					DecRef();
-					closed = true;
-				}
-			}
+		    Dispose();
 		}
 
-        /// <summary>
-        /// .NET
+        /// <summary> Closes files associated with this index.
+        /// Also saves any new deletions to disk.
+        /// No other methods should be called after this has been called.
         /// </summary>
+        /// <throws>  IOException if there is a low-level IO error </throws>
         public void Dispose()
         {
-            Close();
+            Dispose(true);
+        }
+
+        protected virtual void Dispose(bool disposing)
+        {
+            if (disposing)
+            {
+                lock (this)
+                {
+                    if (!closed)
+                    {
+                        DecRef();
+                        closed = true;
+                    }
+                }
+            }
         }
 		
 		/// <summary>Implements close. </summary>

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexWriter.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexWriter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/IndexWriter.cs Sun Feb 19 09:54:42 2012
@@ -402,7 +402,7 @@ namespace Lucene.Net.Index
 		/// has been called on this instance). 
 		/// </summary>
 		
-		internal class ReaderPool
+		internal class ReaderPool : IDisposable
 		{
 			public ReaderPool(IndexWriter enclosingInstance)
 			{
@@ -544,45 +544,54 @@ namespace Lucene.Net.Index
 					}
 				}
 			}
-			
-			/// <summary>Remove all our references to readers, and commits
-			/// any pending changes. 
-			/// </summary>
-			internal virtual void  Close()
-			{
-                // We invoke deleter.checkpoint below, so we must be
-                // sync'd on IW:
-                // TODO: assert Thread.holdsLock(IndexWriter.this);
-				lock (this)
-				{
-				    var toRemove = new List<SegmentInfo>();
-				    var iter = readerMap.GetEnumerator();
-					while (iter.MoveNext())
-					{
-					    KeyValuePair<SegmentInfo, SegmentReader> ent = iter.Current;
-						SegmentReader sr = ent.Value;
-						if (sr.hasChanges)
-						{
-							System.Diagnostics.Debug.Assert(InfoIsLive(sr.GetSegmentInfo()));
-							sr.DoCommit(null);
-                            // Must checkpoint w/ deleter, because this
-                            // segment reader will have created new _X_N.del
-                            // file.
-                            enclosingInstance.deleter.Checkpoint(enclosingInstance.segmentInfos, false);
-						}
 
-                        toRemove.Add(ent.Key); 
-						
-						// NOTE: it is allowed that this decRef does not
-						// actually close the SR; this can happen when a
-						// near real-time reader is kept open after the
-						// IndexWriter instance is closed
-						sr.DecRef();
-					}
-                    foreach (var key in toRemove)
-                        readerMap.Remove(key);
-				}
-			}
+            /// <summary>Remove all our references to readers, and commits
+            /// any pending changes. 
+            /// </summary>
+		    public void Dispose()
+		    {
+		        Dispose(true);
+		    }
+
+            protected void Dispose(bool disposing)
+            {
+                if (disposing)
+                {
+                    // We invoke deleter.checkpoint below, so we must be
+                    // sync'd on IW:
+                    // TODO: assert Thread.holdsLock(IndexWriter.this);
+                    // TODO: Should this class have bool _isDisposed?
+                    lock (this)
+                    {
+                        //var toRemove = new List<SegmentInfo>();
+                        foreach (var ent in readerMap)
+                        {
+                            SegmentReader sr = ent.Value;
+                            if (sr.hasChanges)
+                            {
+                                System.Diagnostics.Debug.Assert(InfoIsLive(sr.GetSegmentInfo()));
+                                sr.DoCommit(null);
+                                // Must checkpoint w/ deleter, because this
+                                // segment reader will have created new _X_N.del
+                                // file.
+                                enclosingInstance.deleter.Checkpoint(enclosingInstance.segmentInfos, false);
+                            }
+
+                            //toRemove.Add(ent.Key);
+
+                            // NOTE: it is allowed that this decRef does not
+                            // actually close the SR; this can happen when a
+                            // near real-time reader is kept open after the
+                            // IndexWriter instance is closed
+                            sr.DecRef();
+                        }
+
+                        //foreach (var key in toRemove)
+                        //    readerMap.Remove(key);
+                        readerMap.Clear();
+                    }
+                }
+            }
 			
 			/// <summary> Commit all segment reader in the pool.</summary>
 			/// <throws>  IOException </throws>
@@ -1851,17 +1860,102 @@ namespace Lucene.Net.Index
 		/// </summary>
 		/// <throws>  CorruptIndexException if the index is corrupt </throws>
 		/// <throws>  IOException if there is a low-level IO error </throws>
-		public virtual void  Close()
+		[Obsolete("Use Dispose() instead")]
+		public void Close()
 		{
-			Close(true);
+		    Dispose(true);
 		}
 
-        /// <summary>
-        /// .NET
+        /// <summary> Commits all changes to an index and closes all
+        /// associated files.  Note that this may be a costly
+        /// operation, so, try to re-use a single writer instead of
+        /// closing and opening a new one.  See <see cref="Commit()" /> for
+        /// caveats about write caching done by some IO devices.
+        /// 
+        /// <p/> If an Exception is hit during close, eg due to disk
+        /// full or some other reason, then both the on-disk index
+        /// and the internal state of the IndexWriter instance will
+        /// be consistent.  However, the close will not be complete
+        /// even though part of it (flushing buffered documents)
+        /// may have succeeded, so the write lock will still be
+        /// held.<p/>
+        /// 
+        /// <p/> If you can correct the underlying cause (eg free up
+        /// some disk space) then you can call close() again.
+        /// Failing that, if you want to force the write lock to be
+        /// released (dangerous, because you may then lose buffered
+        /// docs in the IndexWriter instance) then you can do
+        /// something like this:<p/>
+        /// 
+        /// <code>
+        /// try {
+        ///     writer.close();
+        /// } finally {
+        ///     if (IndexWriter.isLocked(directory)) {
+        ///         IndexWriter.unlock(directory);
+        ///     }
+        /// }
+        /// </code>
+        /// 
+        /// after which, you must be certain not to use the writer
+        /// instance anymore.<p/>
+        /// 
+        /// <p/><b>NOTE</b>: if this method hits an OutOfMemoryError
+        /// you should immediately close the writer, again.  See <a
+        /// href="#OOME">above</a> for details.<p/>
+        /// 
         /// </summary>
+        /// <throws>  CorruptIndexException if the index is corrupt </throws>
+        /// <throws>  IOException if there is a low-level IO error </throws>
         public virtual void Dispose()
         {
-            Close();
+            Dispose(true);
+        }
+
+        /// <summary> Closes the index with or without waiting for currently
+        /// running merges to finish.  This is only meaningful when
+        /// using a MergeScheduler that runs merges in background
+        /// threads.
+        /// 
+        /// <p/><b>NOTE</b>: if this method hits an OutOfMemoryError
+        /// you should immediately close the writer, again.  See <a
+        /// href="#OOME">above</a> for details.<p/>
+        /// 
+        /// <p/><b>NOTE</b>: it is dangerous to always call
+        /// close(false), especially when IndexWriter is not open
+        /// for very long, because this can result in "merge
+        /// starvation" whereby long merges will never have a
+        /// chance to finish.  This will cause too many segments in
+        /// your index over time.<p/>
+        /// 
+        /// </summary>
+        /// <param name="waitForMerges">if true, this call will block
+        /// until all merges complete; else, it will ask all
+        /// running merges to abort, wait until those merges have
+        /// finished (which should be at most a few seconds), and
+        /// then return.
+        /// </param>
+        public virtual void Dispose(bool waitForMerges)
+        {
+            Dispose(true, waitForMerges);
+        }
+
+        protected virtual void Dispose(bool disposing, bool waitForMerges)
+        {
+            if (disposing)
+            {
+                // Ensure that only one thread actually gets to do the closing:
+                if (ShouldClose())
+                {
+                    // If any methods have hit OutOfMemoryError, then abort
+                    // on close, in case the internal state of IndexWriter
+                    // or DocumentsWriter is corrupt
+                    if (hitOOM)
+                        RollbackInternal();
+                    else
+                        CloseInternal(waitForMerges);
+                }
+            }
         }
 		
 		/// <summary> Closes the index with or without waiting for currently
@@ -1887,20 +1981,10 @@ namespace Lucene.Net.Index
 		/// finished (which should be at most a few seconds), and
 		/// then return.
 		/// </param>
-		public virtual void  Close(bool waitForMerges)
+		[Obsolete("Use Dispose(bool) instead")]
+		public virtual void Close(bool waitForMerges)
 		{
-			
-			// Ensure that only one thread actually gets to do the closing:
-			if (ShouldClose())
-			{
-				// If any methods have hit OutOfMemoryError, then abort
-				// on close, in case the internal state of IndexWriter
-				// or DocumentsWriter is corrupt
-				if (hitOOM)
-					RollbackInternal();
-				else
-					CloseInternal(waitForMerges);
-			}
+		    Dispose(waitForMerges);
 		}
 		
 		// Returns true if this thread should attempt to close, or
@@ -1933,7 +2017,7 @@ namespace Lucene.Net.Index
 			}
 		}
 		
-		private void  CloseInternal(bool waitForMerges)
+		private void CloseInternal(bool waitForMerges)
 		{
 			
 			docWriter.PauseAllThreads();
@@ -1943,7 +2027,7 @@ namespace Lucene.Net.Index
 				if (infoStream != null)
 					Message("now flush at close");
 				
-				docWriter.Close();
+				docWriter.Dispose();
 				
 				// Only allow a new merge to be triggered if we are
 				// going to wait for merges:
@@ -1977,9 +2061,9 @@ namespace Lucene.Net.Index
 				
 				lock (this)
 				{
-					readerPool.Close();
+					readerPool.Dispose();
 					docWriter = null;
-					deleter.Close();
+					deleter.Dispose();
 				}
 				
 				if (writeLock != null)

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogByteSizeMergePolicy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogByteSizeMergePolicy.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogByteSizeMergePolicy.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogByteSizeMergePolicy.cs Sun Feb 19 09:54:42 2012
@@ -47,6 +47,11 @@ namespace Lucene.Net.Index
 		{
 			return SizeBytes(info);
 		}
+
+        protected override void Dispose(bool disposing)
+        {
+            // Do nothing.
+        }
 		
 		/// <summary><p/>Determines the largest segment (measured by total
 		/// byte size of the segment's files, in MB) that may be

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogDocMergePolicy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogDocMergePolicy.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogDocMergePolicy.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogDocMergePolicy.cs Sun Feb 19 09:54:42 2012
@@ -59,7 +59,12 @@ namespace Lucene.Net.Index
 		{
 			minMergeSize = minMergeDocs;
 		}
-		
+
+        protected override void Dispose(bool disposing)
+        {
+            // Do nothing.
+        }
+
 		/// <summary>Get the minimum size for a segment to remain
 		/// un-merged.
 		/// </summary>

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogMergePolicy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogMergePolicy.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogMergePolicy.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/LogMergePolicy.cs Sun Feb 19 09:54:42 2012
@@ -206,17 +206,6 @@ namespace Lucene.Net.Index
 			return calibrateSizeByDeletes;
 		}
 		
-        [Obsolete("This method is being replaced by Dispose()")]
-		public override void  Close()
-		{
-            Dispose();
-		}
-
-        public override void Dispose()
-        {
-            //wow do nothing!
-        }
-		
 		abstract protected internal long Size(SegmentInfo info);
 		
 		protected internal virtual long SizeDocs(SegmentInfo info)

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MergePolicy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MergePolicy.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MergePolicy.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MergePolicy.cs Sun Feb 19 09:54:42 2012
@@ -281,11 +281,19 @@ namespace Lucene.Net.Index
 		public abstract MergeSpecification FindMergesToExpungeDeletes(SegmentInfos segmentInfos);
 
         /// <summary> Release all resources for the policy.</summary>
-        [Obsolete("This method is being replaced by Dispose()")]
-		public abstract void  Close();
+        [Obsolete("Use Dispose() instead")]
+		public void Close()
+        {
+            Dispose();
+        }
 
         /// <summary> Release all resources for the policy.</summary>
-	    public abstract void Dispose();
+	    public void Dispose()
+	    {
+	        Dispose(true);
+	    }
+
+	    protected abstract void Dispose(bool disposing);
 		
 		/// <summary> Returns true if a newly flushed (not from merge)
 		/// segment should use the compound file format.

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MergeScheduler.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MergeScheduler.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MergeScheduler.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MergeScheduler.cs Sun Feb 19 09:54:42 2012
@@ -35,13 +35,24 @@ namespace Lucene.Net.Index
 	/// these APIs.
 	/// </summary>
 	
-	public abstract class MergeScheduler
+	public abstract class MergeScheduler : IDisposable
 	{
 		
 		/// <summary>Run the merges provided by <see cref="IndexWriter.GetNextMerge()" />. </summary>
 		public abstract void  Merge(IndexWriter writer);
 		
-		/// <summary>Close this MergeScheduler. </summary>
-		public abstract void  Close();
+        [Obsolete("Use Dispose() instead")]
+		public void Close()
+        {
+            Dispose();
+        }
+
+        public void Dispose()
+        {
+            Dispose(true);
+        }
+
+	    /// <summary>Close this MergeScheduler. </summary>
+	    protected abstract void Dispose(bool disposing);
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MultiLevelSkipListReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MultiLevelSkipListReader.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MultiLevelSkipListReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MultiLevelSkipListReader.cs Sun Feb 19 09:54:42 2012
@@ -31,7 +31,7 @@ namespace Lucene.Net.Index
 	/// Subclasses must implement the abstract method <see cref="ReadSkipData(int, IndexInput)" />
 	/// which defines the actual format of the skip data.
 	/// </summary>
-	abstract class MultiLevelSkipListReader
+	abstract class MultiLevelSkipListReader : IDisposable
 	{
 		// the maximum number of skip levels possible for this index
 		private int maxNumberOfSkipLevels;
@@ -50,6 +50,8 @@ namespace Lucene.Net.Index
 		
 		private int docCount;
 		private bool haveSkipped;
+
+	    private bool isDisposed;
 		
 		private IndexInput[] skipStream; // skipStream for each level
 		private long[] skipPointer; // the start pointer of each skip level
@@ -175,17 +177,29 @@ namespace Lucene.Net.Index
 				childPointer[level] = skipStream[level].ReadVLong() + skipPointer[level - 1];
 			}
 		}
-		
-		internal virtual void  Close()
-		{
-			for (int i = 1; i < skipStream.Length; i++)
-			{
-				if (skipStream[i] != null)
-				{
-					skipStream[i].Close();
-				}
-			}
-		}
+
+        public void Dispose()
+        {
+            Dispose(true);
+        }
+
+        protected virtual void Dispose(bool disposing)
+        {
+            if (isDisposed) return;
+
+            if (disposing)
+            {
+                for (int i = 1; i < skipStream.Length; i++)
+                {
+                    if (skipStream[i] != null)
+                    {
+                        skipStream[i].Close();
+                    }
+                }
+            }
+
+            isDisposed = true;
+        }
 		
 		/// <summary>initializes the reader </summary>
 		internal virtual void  Init(long skipPointer, int df)

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MultipleTermPositions.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MultipleTermPositions.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MultipleTermPositions.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/MultipleTermPositions.cs Sun Feb 19 09:54:42 2012
@@ -107,7 +107,8 @@ namespace Lucene.Net.Index
 		private int _freq;
 		private TermPositionsQueue _termPositionsQueue;
 		private IntQueue _posList;
-		
+
+	    private bool isDisposed;
 		/// <summary> Creates a new <c>MultipleTermPositions</c> instance.
 		/// 
 		/// </summary>
@@ -184,6 +185,7 @@ namespace Lucene.Net.Index
 			return _freq;
 		}
 		
+        [Obsolete("Use Dispose() instead")]
 		public void  Close()
 		{
 		    Dispose();
@@ -191,8 +193,20 @@ namespace Lucene.Net.Index
 
         public void Dispose()
         {
-            while (_termPositionsQueue.Size() > 0)
-                _termPositionsQueue.Pop().Close();
+            Dispose(true);
+        }
+
+        protected virtual void Dispose(bool disposing)
+        {
+            if (isDisposed) return;
+            
+            if (disposing)
+            {
+                while (_termPositionsQueue.Size() > 0)
+                    _termPositionsQueue.Pop().Close();
+            }
+
+            isDisposed = true;
         }
 		
 		/// <summary> Not implemented.</summary>

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ParallelReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ParallelReader.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ParallelReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ParallelReader.cs Sun Feb 19 09:54:42 2012
@@ -535,7 +535,7 @@ namespace Lucene.Net.Index
 			return fieldSet;
 		}
 		
-		private class ParallelTermEnum:TermEnum
+		private class ParallelTermEnum : TermEnum
 		{
 			private void  InitBlock(ParallelReader enclosingInstance)
 			{
@@ -553,6 +553,8 @@ namespace Lucene.Net.Index
 			private System.String field;
 			private IEnumerator<string> fieldIterator;
 			private TermEnum termEnum;
+
+		    private bool isDisposed;
 			
 			public ParallelTermEnum(ParallelReader enclosingInstance)
 			{
@@ -632,16 +634,18 @@ namespace Lucene.Net.Index
 				
 				return termEnum.DocFreq();
 			}
-			
-			public override void  Close()
-			{
-			    Dispose();
-			}
 
-            public override void Dispose()
+            protected override void Dispose(bool disposing)
             {
-                if (termEnum != null)
-                    termEnum.Close();
+                if (isDisposed) return;
+
+                if (disposing)
+                {
+                    if (termEnum != null)
+                        termEnum.Close();
+                }
+
+                isDisposed = true;
             }
 		}
 		
@@ -662,6 +666,8 @@ namespace Lucene.Net.Index
 				
 			}
 			protected internal TermDocs termDocs;
+
+		    private bool isDisposed;
 			
 			public ParallelTermDocs(ParallelReader enclosingInstance)
 			{
@@ -721,16 +727,29 @@ namespace Lucene.Net.Index
 				
 				return termDocs.SkipTo(target);
 			}
-			
-			public virtual void  Close()
-			{
-			    Dispose();
-			}
 
-            public virtual void Dispose()
+            [Obsolete("Use Dispose() instead")]
+            public virtual void Close()
+            {
+                Dispose();
+            }
+
+		    public void Dispose()
+		    {
+		        Dispose(true);
+		    }
+
+            protected virtual void Dispose(bool disposing)
             {
-                if (termDocs != null)
-                    termDocs.Close();
+                if (isDisposed) return;
+
+                if (disposing)
+                {
+                    if (termDocs != null)
+                        termDocs.Close();
+                }
+
+                isDisposed = true;
             }
 		}
 		

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ReusableStringReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ReusableStringReader.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ReusableStringReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/ReusableStringReader.cs Sun Feb 19 09:54:42 2012
@@ -36,10 +36,12 @@ namespace Lucene.Net.Index
             left = s.Length;
             this.upto = 0;
         }
+
         public int Read(char[] c)
         {
             return Read(c, 0, c.Length);
         }
+
         public override int Read(System.Char[] c, int off, int len)
         {
             if (left > len)
@@ -64,11 +66,13 @@ namespace Lucene.Net.Index
                 return r;
             }
         }
+
+        [Obsolete("Use Dispose() instead")]
         public override void Close()
         {
+            Dispose();
         }
 
-
         public override int Read()
         {
             if (left > 0)

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMergeInfo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMergeInfo.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMergeInfo.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMergeInfo.cs Sun Feb 19 09:54:42 2012
@@ -20,7 +20,7 @@ using System;
 namespace Lucene.Net.Index
 {
 	
-	sealed class SegmentMergeInfo
+	sealed class SegmentMergeInfo : IDisposable
 	{
 		internal Term term;
 		internal int base_Renamed;
@@ -30,6 +30,8 @@ namespace Lucene.Net.Index
 		internal int delCount;
 		private TermPositions postings; // use getPositions()
 		private int[] docMap; // use getDocMap()
+
+	    private bool isDisposed;
 		
 		internal SegmentMergeInfo(int b, TermEnum te, IndexReader r)
 		{
@@ -88,14 +90,19 @@ namespace Lucene.Net.Index
 				return false;
 			}
 		}
-		
-		internal void  Close()
-		{
-			termEnum.Close();
-			if (postings != null)
-			{
-				postings.Close();
-			}
-		}
+
+        public void Dispose()
+        {
+            if (isDisposed) return;
+
+            // Move to protected method if class becomes unsealed
+            termEnum.Close();
+            if (postings != null)
+            {
+                postings.Close();
+            }
+
+            isDisposed = true;
+        }
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMergeQueue.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMergeQueue.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMergeQueue.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMergeQueue.cs Sun Feb 19 09:54:42 2012
@@ -21,7 +21,7 @@ using Lucene.Net.Util;
 namespace Lucene.Net.Index
 {
 	
-	sealed class SegmentMergeQueue : PriorityQueue<SegmentMergeInfo>
+	sealed class SegmentMergeQueue : PriorityQueue<SegmentMergeInfo>, IDisposable
 	{
 		internal SegmentMergeQueue(int size)
 		{
@@ -36,11 +36,12 @@ namespace Lucene.Net.Index
 			else
 				return comparison < 0;
 		}
-		
-		internal void  Close()
-		{
-			while (Top() != null)
-				Pop().Close();
-		}
+
+	    public void Dispose()
+	    {
+            // Move to protected method if class becomes unsealed
+            while (Top() != null)
+                Pop().Dispose();
+	    }
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMerger.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMerger.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMerger.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentMerger.cs Sun Feb 19 09:54:42 2012
@@ -222,11 +222,11 @@ namespace Lucene.Net.Index
 		/// Should not be called before merge().
 		/// </summary>
 		/// <throws>  IOException </throws>
-		public /*internal*/ void  CloseReaders()
+		internal void  CloseReaders()
 		{
 			foreach(IndexReader reader in readers)
 			{
-				reader.Close();
+				reader.Dispose();
 			}
 		}
 
@@ -421,7 +421,7 @@ namespace Lucene.Net.Index
 				}
 				finally
 				{
-					fieldsWriter.Close();
+					fieldsWriter.Dispose();
 				}
 				
 				System.String fileName = segment + "." + IndexFileNames.FIELDS_INDEX_EXTENSION;
@@ -572,7 +572,7 @@ namespace Lucene.Net.Index
 			}
 			finally
 			{
-				termVectorsWriter.Close();
+				termVectorsWriter.Dispose();
 			}
 			
 			System.String fileName = segment + "." + IndexFileNames.VECTORS_INDEX_EXTENSION;
@@ -690,7 +690,7 @@ namespace Lucene.Net.Index
 			{
 				consumer.Finish();
 				if (queue != null)
-					queue.Close();
+					queue.Dispose();
 			}
 		}
 		
@@ -725,7 +725,7 @@ namespace Lucene.Net.Index
 					queue.Add(smi);
 				// initialize queue
 				else
-					smi.Close();
+					smi.Dispose();
 			}
 			
 			SegmentMergeInfo[] match = new SegmentMergeInfo[readers.Count];
@@ -767,7 +767,7 @@ namespace Lucene.Net.Index
 						queue.Add(smi);
 					// restore queue
 					else
-						smi.Close(); // done with a segment
+						smi.Dispose(); // done with a segment
 				}
 			}
 		}

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentReader.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentReader.cs Sun Feb 19 09:54:42 2012
@@ -265,14 +265,14 @@ namespace Lucene.Net.Index
 						// close everything, nothing is shared anymore with other readers
 						if (tis != null)
 						{
-							tis.Close();
+							tis.Dispose();
 							// null so if an app hangs on to us we still free most ram
 							tis = null;
 						}
 						
 						if (tisNoIndex != null)
 						{
-							tisNoIndex.Close();
+							tisNoIndex.Dispose();
 						}
 						
 						if (freqStream != null)
@@ -287,12 +287,12 @@ namespace Lucene.Net.Index
 						
 						if (termVectorsReaderOrig != null)
 						{
-							termVectorsReaderOrig.Close();
+							termVectorsReaderOrig.Dispose();
 						}
 						
 						if (fieldsReaderOrig != null)
 						{
-							fieldsReaderOrig.Close();
+                            fieldsReaderOrig.Dispose();
 						}
 						
 						if (cfsReader != null)
@@ -517,7 +517,7 @@ namespace Lucene.Net.Index
 					if (in_Renamed != Enclosing_Instance.singleNormStream)
 					{
 						// It's private to us -- just close it
-						in_Renamed.Close();
+						in_Renamed.Dispose();
 					}
 					else
 					{
@@ -525,7 +525,7 @@ namespace Lucene.Net.Index
 						// maybe close the shared norm stream
 						if (Enclosing_Instance.singleNormRef.DecRef() == 0)
 						{
-							Enclosing_Instance.singleNormStream.Close();
+							Enclosing_Instance.singleNormStream.Dispose();
 							Enclosing_Instance.singleNormStream = null;
 						}
 					}

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermDocs.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermDocs.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermDocs.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermDocs.cs Sun Feb 19 09:54:42 2012
@@ -23,7 +23,7 @@ using BitVector = Lucene.Net.Util.BitVec
 namespace Lucene.Net.Index
 {
 	
-	public class SegmentTermDocs : TermDocs
+	internal class SegmentTermDocs : TermDocs
 	{
 		protected internal SegmentReader parent;
 		protected internal IndexInput freqStream;
@@ -45,6 +45,8 @@ namespace Lucene.Net.Index
 		
 		protected internal bool currentFieldStoresPayloads;
 		protected internal bool currentFieldOmitTermFreqAndPositions;
+
+	    private bool isDisposed;
 		
 		public /*protected internal*/ SegmentTermDocs(SegmentReader parent)
 		{
@@ -108,17 +110,27 @@ namespace Lucene.Net.Index
 				haveSkipped = false;
 			}
 		}
-		
-		public virtual void  Close()
-		{
-		    Dispose();
-		}
 
-        public virtual void Dispose()
+        public void Dispose()
+        {
+            Dispose(true);
+        }
+
+        [Obsolete("Use Dispose() instead")]
+        public void Close()
+        {
+            Dispose();
+        }
+
+        protected virtual void Dispose(bool disposing)
         {
-            freqStream.Close();
+            if (isDisposed) return;
+
+            freqStream.Dispose();
             if (skipListReader != null)
-                skipListReader.Close();
+                skipListReader.Dispose();
+
+            isDisposed = true;
         }
 		
 		public int Doc()
@@ -266,7 +278,7 @@ namespace Lucene.Net.Index
 			return true;
 		}
 
-        public IndexInput freqStream_ForNUnit
+	    public IndexInput freqStream_ForNUnit
         {
             get { return freqStream; }
             set { freqStream = value; }

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermEnum.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermEnum.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermEnum.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermEnum.cs Sun Feb 19 09:54:42 2012
@@ -21,8 +21,7 @@ using IndexInput = Lucene.Net.Store.Inde
 
 namespace Lucene.Net.Index
 {
-	
-	public sealed class SegmentTermEnum:TermEnum, System.ICloneable
+	internal sealed class SegmentTermEnum : TermEnum, System.ICloneable
 	{
 		private IndexInput input;
 		internal FieldInfos fieldInfos;
@@ -242,12 +241,7 @@ namespace Lucene.Net.Index
 		}
 		
 		/// <summary>Closes the enumeration to further activity, freeing resources. </summary>
-		public override void  Close()
-		{
-            Dispose();
-		}
-
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
             input.Close();
         }

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermPositions.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermPositions.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermPositions.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SegmentTermPositions.cs Sun Feb 19 09:54:42 2012
@@ -21,8 +21,7 @@ using IndexInput = Lucene.Net.Store.Inde
 
 namespace Lucene.Net.Index
 {
-	
-	public sealed class SegmentTermPositions:SegmentTermDocs, TermPositions
+	internal sealed class SegmentTermPositions : SegmentTermDocs, TermPositions
 	{
 		private IndexInput proxStream;
 		private int proxCount;
@@ -56,14 +55,9 @@ namespace Lucene.Net.Index
 			needToLoadPayload = false;
 		}
 		
-		public override void  Close()
-		{
-            Dispose();
-		}
-
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            base.Dispose();
+            base.Dispose(disposing);
             if (proxStream != null)
                 proxStream.Close();
         }

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SerialMergeScheduler.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SerialMergeScheduler.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SerialMergeScheduler.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/SerialMergeScheduler.cs Sun Feb 19 09:54:42 2012
@@ -43,9 +43,9 @@ namespace Lucene.Net.Index
 				}
 			}
 		}
-		
-		public override void  Close()
-		{
-		}
+
+	    protected override void Dispose(bool disposing)
+	    {
+	    }
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/StoredFieldsWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/StoredFieldsWriter.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/StoredFieldsWriter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/StoredFieldsWriter.cs Sun Feb 19 09:54:42 2012
@@ -102,7 +102,7 @@ namespace Lucene.Net.Index
 				
 				if (fieldsWriter != null)
 				{
-					fieldsWriter.Close();
+					fieldsWriter.Dispose();
 					fieldsWriter = null;
 					lastDocID = 0;
 					System.Diagnostics.Debug.Assert(state.docStoreSegmentName != null);
@@ -152,7 +152,7 @@ namespace Lucene.Net.Index
 				{
 					try
 					{
-						fieldsWriter.Close();
+						fieldsWriter.Dispose();
 					}
 					catch (System.Exception t)
 					{

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermDocs.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermDocs.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermDocs.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermDocs.cs Sun Feb 19 09:54:42 2012
@@ -78,6 +78,7 @@ namespace Lucene.Net.Index
 		/// </summary>
 		bool SkipTo(int target);
 		
+        // TODO: Determine which release this will be removed from
 		/// <summary>Frees associated resources. </summary>
 		[Obsolete("Use Dispose() instead")]
 		void  Close();

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermEnum.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermEnum.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermEnum.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermEnum.cs Sun Feb 19 09:54:42 2012
@@ -34,10 +34,20 @@ namespace Lucene.Net.Index
 		
 		/// <summary>Returns the docFreq of the current Term in the enumeration.</summary>
 		public abstract int DocFreq();
-		
-		/// <summary>Closes the enumeration to further activity, freeing resources. </summary>
-		public abstract void  Close();
 
-	    public abstract void Dispose();
+        /// <summary>Closes the enumeration to further activity, freeing resources. </summary>
+        [Obsolete("Use Dispose() instead")]
+        public void Close()
+        {
+            Dispose();
+        }
+
+	    /// <summary>Closes the enumeration to further activity, freeing resources. </summary>
+	    public void Dispose()
+	    {
+	        Dispose(true);
+	    }
+
+	    protected abstract void Dispose(bool disposing);
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermInfosReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermInfosReader.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermInfosReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermInfosReader.cs Sun Feb 19 09:54:42 2012
@@ -29,12 +29,14 @@ namespace Lucene.Net.Index
 	/// set.  
 	/// </summary>
 	
-	sealed class TermInfosReader
+	sealed class TermInfosReader : IDisposable
 	{
 		private Directory directory;
 		private System.String segment;
 		private FieldInfos fieldInfos;
-		
+
+        private bool isDisposed;
+
 		private CloseableThreadLocal<ThreadResources> threadResources = new CloseableThreadLocal<ThreadResources>();
 		private SegmentTermEnum origEnum;
 		private long size;
@@ -124,7 +126,7 @@ namespace Lucene.Net.Index
 				// wait for a GC to do so.
 				if (!success)
 				{
-					Close();
+					Dispose();
 				}
 			}
 		}
@@ -138,13 +140,18 @@ namespace Lucene.Net.Index
 		{
 			return origEnum.maxSkipLevels;
 		}
-		
-		internal void  Close()
-		{
-			if (origEnum != null)
-				origEnum.Close();
-			threadResources.Close();
-		}
+
+        public void Dispose()
+        {
+            if (isDisposed) return;
+
+            // Move to protected method if class becomes unsealed
+            if (origEnum != null)
+                origEnum.Dispose();
+            threadResources.Dispose();
+
+            isDisposed = true;
+        }
 		
 		/// <summary>Returns the number of term/value pairs in the set. </summary>
 		internal long Size()

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermInfosWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermInfosWriter.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermInfosWriter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermInfosWriter.cs Sun Feb 19 09:54:42 2012
@@ -28,7 +28,7 @@ namespace Lucene.Net.Index
 	/// Directory.  A TermInfos can be written once, in order.  
 	/// </summary>
 	
-	sealed class TermInfosWriter
+	sealed class TermInfosWriter : IDisposable
 	{
 		/// <summary>The file format version, a negative number. </summary>
 		public const int FORMAT = - 3;
@@ -39,7 +39,9 @@ namespace Lucene.Net.Index
 		
 		// NOTE: always change this if you switch to a new format!
 		public static readonly int FORMAT_CURRENT = FORMAT_VERSION_UTF8_LENGTH_IN_BYTES;
-		
+
+        private bool isDisposed;
+
 		private FieldInfos fieldInfos;
 		private IndexOutput output;
 		private TermInfo lastTi = new TermInfo();
@@ -230,14 +232,19 @@ namespace Lucene.Net.Index
 		}
 		
 		/// <summary>Called to complete TermInfos creation. </summary>
-		internal void  Close()
+		public void Dispose()
 		{
+            // Move to protected method if class becomes unsealed
+            if (isDisposed) return;
+
 			output.Seek(4); // write size after format
 			output.WriteLong(size);
-			output.Close();
+            output.Dispose();
 			
 			if (!isIndex)
-				other.Close();
+				other.Dispose();
+
+		    isDisposed = true;
 		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermPositions.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermPositions.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermPositions.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermPositions.cs Sun Feb 19 09:54:42 2012
@@ -29,7 +29,7 @@ namespace Lucene.Net.Index
 	/// <seealso cref="IndexReader.TermPositions()">
 	/// </seealso>
 	
-	public interface TermPositions:TermDocs
+	public interface TermPositions : TermDocs
 	{
 		/// <summary>Returns next position in the current document.  It is an error to call
 		/// this more than <see cref="TermDocs.Freq()" /> times

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermVectorsReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermVectorsReader.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermVectorsReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermVectorsReader.cs Sun Feb 19 09:54:42 2012
@@ -23,7 +23,7 @@ using IndexInput = Lucene.Net.Store.Inde
 
 namespace Lucene.Net.Index
 {
-	public class TermVectorsReader : System.ICloneable
+	class TermVectorsReader : System.ICloneable, IDisposable
 	{
 		
 		// NOTE: if you make a new format, it must be larger than
@@ -58,8 +58,9 @@ namespace Lucene.Net.Index
 		private int docStoreOffset;
 		
 		private int format;
-		
-		public /*internal*/ TermVectorsReader(Directory d, System.String segment, FieldInfos fieldInfos):this(d, segment, fieldInfos, BufferedIndexInput.BUFFER_SIZE)
+	    private bool isDisposed;
+
+	    internal TermVectorsReader(Directory d, System.String segment, FieldInfos fieldInfos):this(d, segment, fieldInfos, BufferedIndexInput.BUFFER_SIZE)
 		{
 		}
 		
@@ -133,7 +134,7 @@ namespace Lucene.Net.Index
 				// wait for a GC to do so.
 				if (!success)
 				{
-					Close();
+					Dispose();
 				}
 			}
 		}
@@ -236,45 +237,57 @@ namespace Lucene.Net.Index
 			return format;
 		}
 		
-		internal virtual void  Close()
+        public void Dispose()
+        {
+            Dispose(true);
+        }
+
+		protected virtual void Dispose(bool disposing)
 		{
-			// make all effort to close up. Keep the first exception
-			// and throw it as a new one.
-			System.IO.IOException keep = null;
-			if (tvx != null)
-				try
-				{
-					tvx.Close();
-				}
-				catch (System.IO.IOException e)
-				{
-					if (keep == null)
-						keep = e;
-				}
-			if (tvd != null)
-				try
-				{
-					tvd.Close();
-				}
-				catch (System.IO.IOException e)
-				{
-					if (keep == null)
-						keep = e;
-				}
-			if (tvf != null)
-				try
-				{
-					tvf.Close();
-				}
-				catch (System.IO.IOException e)
-				{
-					if (keep == null)
-						keep = e;
-				}
-			if (keep != null)
-			{
-                throw new System.IO.IOException(keep.StackTrace);
-			}
+            if (isDisposed) return;
+
+            if (disposing)
+            {
+                // make all effort to close up. Keep the first exception
+                // and throw it as a new one.
+                System.IO.IOException keep = null;
+                if (tvx != null)
+                    try
+                    {
+                        tvx.Close();
+                    }
+                    catch (System.IO.IOException e)
+                    {
+                        if (keep == null)
+                            keep = e;
+                    }
+                if (tvd != null)
+                    try
+                    {
+                        tvd.Close();
+                    }
+                    catch (System.IO.IOException e)
+                    {
+                        if (keep == null)
+                            keep = e;
+                    }
+                if (tvf != null)
+                    try
+                    {
+                        tvf.Close();
+                    }
+                    catch (System.IO.IOException e)
+                    {
+                        if (keep == null)
+                            keep = e;
+                    }
+                if (keep != null)
+                {
+                    throw new System.IO.IOException(keep.StackTrace);
+                }
+            }
+
+		    isDisposed = true;
 		}
 		
 		/// <summary> </summary>

Modified: incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermVectorsWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermVectorsWriter.cs?rev=1290981&r1=1290980&r2=1290981&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermVectorsWriter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net.3.0.3/trunk/src/core/Index/TermVectorsWriter.cs Sun Feb 19 09:54:42 2012
@@ -24,8 +24,7 @@ using UnicodeUtil = Lucene.Net.Util.Unic
 
 namespace Lucene.Net.Index
 {
-	
-	sealed class TermVectorsWriter
+	sealed class TermVectorsWriter : IDisposable
 	{
 		
 		private IndexOutput tvx = null, tvd = null, tvf = null;
@@ -201,8 +200,10 @@ namespace Lucene.Net.Index
 		}
 		
 		/// <summary>Close all streams. </summary>
-		internal void  Close()
+		public void Dispose()
 		{
+            // Move to a protected method if class becomes unsealed
+
 			// make an effort to close all streams we can but remember and re-throw
 			// the first exception encountered in this process
 			System.IO.IOException keep = null;



Mime
View raw message