Shop OBEX P1 Docs P2 Docs Learn Events
Best Practice to reset a StringBuffer var — Parallax Forums

Best Practice to reset a StringBuffer var

Sarge516Sarge516 Posts: 6
edited 2008-12-08 01:38 in General Discussion
I want to manage memory well but a little confused about resetting StringBuffer vars and it's impact

static public StringBuffer mySB = new StringBuffer("OK by me");

... processing code

Now I want to reset the value in mySB to "Too Bad";

Is it OK to do the following or is there a better way ?

mySB = new StringBuffer("Too Bad");


Thanks!

scool.gifscool.gif

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-12-07 23:40
    If you do that, the old StringBuffer still exists (there is no garbage collection)
    but you have lost its reference.
    Better way:
    mySB.clear(); //clear the existing instance
    mySB.append("Too Bad"); //append new string

    regards peter
  • Sarge516Sarge516 Posts: 6
    edited 2008-12-08 01:38
    Thanks, I see I have some new methods to learn!
Sign In or Register to comment.