[Snowball-discuss] Re: Possible memory leak in Snowballs Java stemmer
Richard Boulton
richard@tartarus.org
Mon Jun 7 10:51:02 2004
This is a multi-part message in MIME format.
--------------000000050708030209050502
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
I have applied the attached patch to fix this problem. The java sources
distributed on the snowball website now contain the updated code.
--
Richard
--------------000000050708030209050502
Content-Type: text/plain;
name="diffs"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="diffs"
Index: SnowballProgram.java
===================================================================
RCS file: /home/cvs/snowball/website/net/sf/snowball/SnowballProgram.java,v
retrieving revision 1.2
diff -u -r1.2 SnowballProgram.java
--- SnowballProgram.java 28 Jan 2002 19:35:51 -0000 1.2
+++ SnowballProgram.java 7 Jun 2004 09:12:31 -0000
@@ -27,7 +27,15 @@
*/
public String getCurrent()
{
- return current.toString();
+ String result = current.toString();
+ // Make a new StringBuffer. If we reuse the old one, and a user of
+ // the library keeps a reference to the buffer returned (for example,
+ // by converting it to a String in a way which doesn't force a copy),
+ // the buffer size will not decrease, and we will risk wasting a large
+ // amount of memory.
+ // Thanks to Wolfram Esser for spotting this problem.
+ current = new StringBuffer();
+ return result;
}
// current string
--------------000000050708030209050502--