Index: CHANGES.txt =================================================================== --- CHANGES.txt (revision 928716) +++ CHANGES.txt (working copy) @@ -48,6 +48,10 @@ (for example, text:foo^0) sorted incorrectly and produced invalid docids. (yonik) + * LUCENE-2422: Don't reuse byte[] in IndexInput/Output -- it gains + little performance, and ties up possibly large amounts of memory + for apps that index large docs. (Ross Woolf via Mike McCandless) + API Changes * LUCENE-2190: Added a new class CustomScoreProvider to function package Index: src/java/org/apache/lucene/store/IndexInput.java =================================================================== --- src/java/org/apache/lucene/store/IndexInput.java (revision 918466) +++ src/java/org/apache/lucene/store/IndexInput.java (working copy) @@ -26,7 +26,6 @@ * @see Directory */ public abstract class IndexInput implements Cloneable { - private byte[] bytes; // used by readString() private char[] chars; // used by readModifiedUTF8String() private boolean preUTF8Strings; // true if we are reading old (modified UTF8) string format @@ -121,8 +120,7 @@ if (preUTF8Strings) return readModifiedUTF8String(); int length = readVInt(); - if (bytes == null || length > bytes.length) - bytes = new byte[(int) (length*1.25)]; + final byte[] bytes = new byte[length]; readBytes(bytes, 0, length); return new String(bytes, 0, length, "UTF-8"); } @@ -222,7 +220,6 @@ clone = (IndexInput)super.clone(); } catch (CloneNotSupportedException e) {} - clone.bytes = null; clone.chars = null; return clone; Index: src/java/org/apache/lucene/store/IndexOutput.java =================================================================== --- src/java/org/apache/lucene/store/IndexOutput.java (revision 918466) +++ src/java/org/apache/lucene/store/IndexOutput.java (working copy) @@ -29,8 +29,6 @@ */ public abstract class IndexOutput { - private UnicodeUtil.UTF8Result utf8Result = new UnicodeUtil.UTF8Result(); - /** Writes a single byte. * @see IndexInput#readByte() */ @@ -101,6 +99,7 @@ * @see IndexInput#readString() */ public void writeString(String s) throws IOException { + final UnicodeUtil.UTF8Result utf8Result = new UnicodeUtil.UTF8Result(); UnicodeUtil.UTF16toUTF8(s, 0, s.length(), utf8Result); writeVInt(utf8Result.length); writeBytes(utf8Result.result, 0, utf8Result.length);