Index: src/java/org/apache/lucene/index/TermsHashPerField.java =================================================================== --- src/java/org/apache/lucene/index/TermsHashPerField.java (revision 946977) +++ src/java/org/apache/lucene/index/TermsHashPerField.java (working copy) @@ -71,19 +71,14 @@ void shrinkHash(int targetSize) { assert postingsCompacted || numPostings == 0; - // Cannot use ArrayUtil.shrink because we require power - // of 2: - int newSize = postingsHash.length; - while(newSize >= 8 && newSize/4 > targetSize) { - newSize /= 2; - } - + final int newSize = 4; if (newSize != postingsHash.length) { postingsHash = new RawPostingList[newSize]; postingsHashSize = newSize; postingsHashHalfSize = newSize/2; postingsHashMask = newSize-1; } + Arrays.fill(postingsHash, null); } public void reset() { Index: src/java/org/apache/lucene/index/DocumentsWriter.java =================================================================== --- src/java/org/apache/lucene/index/DocumentsWriter.java (revision 946977) +++ src/java/org/apache/lucene/index/DocumentsWriter.java (working copy) @@ -160,6 +160,13 @@ public boolean testPoint(String name) { return docWriter.writer.testPoint(name); } + + public void clear() { + // don't hold onto doc nor analyzer, in case it is + // largish: + doc = null; + analyzer = null; + } } /** Consumer returns this on each doc. This holds any @@ -819,10 +826,16 @@ try { // This call is not synchronized and does all the // work - final DocWriter perDoc = state.consumer.processDocument(); - + final DocWriter perDoc; + try { + perDoc = state.consumer.processDocument(); + } finally { + docState.clear(); + } + // This call is synchronized but fast finishDocument(state, perDoc); + success = true; } finally { if (!success) { Index: src/java/org/apache/lucene/index/IndexWriter.java =================================================================== --- src/java/org/apache/lucene/index/IndexWriter.java (revision 946977) +++ src/java/org/apache/lucene/index/IndexWriter.java (working copy) @@ -4244,6 +4244,9 @@ // Make sure no threads are actively adding a document. // Returns true if docWriter is currently aborting, in // which case we skip flushing this segment + if (infoStream != null) { + message("flush: now pause all indexing threads"); + } if (docWriter.pauseAllThreads()) { docWriter.resumeAllThreads(); return false;