Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Sep 2007

    StringBuffer question


    I am writing an application that uses StringBuffer.
       private void someMethod() {
          StringBuffer sb = new StringBuffer();
          while (true) {
             // do some stuff with the StringBuffer
          sb = null;
    In the above code is it necessary to invoke the method sb.setLength(0); to make sure that the buffer is cleared? Or is it enough to just set it to null? I am just a little paranoid about memory actually getting released and don't want to leave anything to chance.


  2. #2
    Super Contributor
    Join Date
    Jun 2007

    Re: StringBuffer question

    hi javame.developer well just making it null will be enough, even if u dont make the stringBuffer null it will be fine cause its an local variable which will be collected by gc when its scope ends, which will be end of that function.

Similar Threads

  1. a question about command and a question about s60
    By t4kesting in forum Mobile Java General
    Replies: 0
    Last Post: 2006-01-24, 08:21
  2. Replies: 2
    Last Post: 2004-01-08, 18:36
  3. Unable to append "," to a String or StringBuffer
    By ppresedo in forum Mobile Java General
    Replies: 3
    Last Post: 2003-04-12, 17:07
  4. Sending data using iAcceptedSocket (Urgent question)
    By okegame in forum Bluetooth Technology
    Replies: 1
    Last Post: 1970-01-01, 02:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts