uschindler commented on code in PR #17020:
URL: https://github.com/apache/lucene/pull/17020#discussion_r4573468975


##########
lucene/core/src/test/org/apache/lucene/analysis/tokenattributes/TestCharTermAttributeImpl.java:
##########
@@ -105,6 +106,18 @@ public void testClone() throws Exception {
     assertNotSame(buf, copy.buffer());
   }
 
+  public void testCloneDoesNotRetainBytesOfPreviousTerm() {
+    CharTermAttributeImpl t = new CharTermAttributeImpl();
+    String longTerm = "a".repeat(10_000);
+    t.append(longTerm);
+    t.getBytesRef();
+    t.setEmpty().append("hello");
+    CharTermAttributeImpl copy = t.clone();
+    assertEquals(new BytesRef("hello"), copy.getBytesRef());
+    long ramUsed = RamUsageTester.ramUsed(copy);
+    assertTrue("clone uses " + ramUsed + " bytes", ramUsed < 
longTerm.length());

Review Comment:
   I'd also remove this check. Also the whole test setup is not worth this 
check. IMHO the whole test is obsolete, we don't need to test this.
   Actually the whole thing is not a memory problem alone, it is more kind of 
wrong code - it clones too much. There was no reason to copy the 
BytesRefBuilder at all, the clone can use its own one. The BytesRefBuilder is 
just a helper to construct and append data to the BytesRef, it does not need to 
be coned. Just start with a fresh one.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to