Skip to content

Apache Lucene open-source search software

LUCENE-2556: Improve memory usage after cloning CharTermAttribute

Uwe Schindler9221bfbfab1f
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 5e68a0bbd18..c41c5644114 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -745,6 +745,9 @@ Optimizations
* LUCENE-2098: Improve the performance of BaseCharFilter, especially for
large documents. (Robin Wojciki, Koji Sekiguchi, Robert Muir)
+* LUCENE-2556: Improve memory usage after cloning (Char)TermAttribute.
+ (Adriano Crestani via Uwe Schindler)
+
Build
* LUCENE-2124: Moved the JDK-based collation support from contrib/collation
diff --git a/lucene/src/java/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.java b/lucene/src/java/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.java
index a20ea995a0f..4268abc0db6 100644
--- a/lucene/src/java/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.java
+++ b/lucene/src/java/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.java
@@ -203,7 +203,8 @@ public class CharTermAttributeImpl extends AttributeImpl implements CharTermAttr
public Object clone() {
CharTermAttributeImpl t = (CharTermAttributeImpl)super.clone();
// Do a deep clone
- t.termBuffer = termBuffer.clone();
+ t.termBuffer = new char[this.termLength];
+ System.arraycopy(this.termBuffer, 0, t.termBuffer, 0, this.termLength);
return t;
}