[Snowball-discuss] Re: Possible memory leak in Snowballs Java stemmer

From: Richard Boulton (richard@tartarus.org)
Date: Mon Jun 07 2004 - 10:51:02 BST


I have applied the attached patch to fix this problem. The java sources
distributed on the snowball website now contain the updated code.

-- 
Richard

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



This archive was generated by hypermail 2.1.3 : Thu Sep 20 2007 - 12:02:46 BST