• Post Reply Bookmark Topic Watch Topic
  • New Topic

Memory leak in being use the stringBuffer  RSS feed

 
Eung maeng
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone have the memory leak error while the stringBuffer uses in while loop?

In the application, there are lots of record which needs to append with Stringbuffer.
even though Stringbuffer has been null reguarly, the memory monitoring tool shows the char[] class are eating too many memory.
GC is dropped the heap memory from the char[]. but not enough to avoid the out of memory error.

As per this problem, the memory is glowing to allocate.

I was trying to new Stringbuffer() every 500 times used or null and reuse with stringbuffer.replace(0,last "").

welcome any comments in this matter,
 
Joe Ess
Bartender
Posts: 9440
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StringBuffer does not have a memory leak. You are more than likely creating Strings from the StringBuffer and keeping those around. That means the char[]'s that make up the various Strings are not eligible for garbage collection.
The solution is to either read in records and process them one at a time or in a small batch or increase your VM's size.
By the way, reusing StringBuffer's is not recommended. See the discussion here.
If you are using JDK 1.5 or 1.6, you should use StringBuilder rather than StringBuffer.
[ September 17, 2008: Message edited by: Joe Ess ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!