Index: lucene/src/test/org/apache/lucene/index/TestByteSlices.java =================================================================== --- lucene/src/test/org/apache/lucene/index/TestByteSlices.java (revision 929732) +++ lucene/src/test/org/apache/lucene/index/TestByteSlices.java (working copy) @@ -16,6 +16,7 @@ import java.util.Random; import java.util.ArrayList; +import java.util.List; import org.apache.lucene.util.LuceneTestCase; public class TestByteSlices extends LuceneTestCase { @@ -41,6 +42,13 @@ for(int i=start;i blocks) { + final int size = blocks.size(); + for(int i=0;i blocks); abstract byte[] getByteBlock(boolean trackAllocations); } Index: lucene/src/java/org/apache/lucene/index/DocumentsWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/DocumentsWriter.java (revision 929732) +++ lucene/src/java/org/apache/lucene/index/DocumentsWriter.java (working copy) @@ -207,8 +207,7 @@ // Recycle the blocks final int blockCount = buffers.size(); - final byte[][] blocks = buffers.toArray( new byte[blockCount][] ); - perDocAllocator.recycleByteBlocks(blocks, 0, blockCount); + perDocAllocator.recycleByteBlocks(buffers); buffers.clear(); sizeInBytes = 0; @@ -1285,6 +1284,15 @@ freeByteBlocks.add(blocks[i]); } } + + @Override + void recycleByteBlocks(List blocks) { + synchronized(DocumentsWriter.this) { + final int size = blocks.size(); + for(int i=0;i