String Object creation

Stupid question, but sometimes you need to ask it to move on.

Now that Timer is complete, I report the frame rate of the application. This means I do the following:

  1. Create a Text Node.
  2. set the Text to the frame rate EACH update cycle.

    text.print("Frame rate " + timer.getFrameRate());
  3. When print is called, it causes the Text Node to assign this.text to the parameter text.
  4. So, there is an unused String object sitting out there, one for each update. This builds up to about 20,000 instances and then the garbage collector comes in. There is then a VERY noticable pause while the gc cleans up the mess.

    Question is, how to keep this strings down? StringBuffer is my guess. But I also want it to be easy for the user. That is, creating a StringBuffer is not as nice is "Frame rate " + timer.getFrameRate()

    Any suggestions?

i see your delima, but i dont have a good answer… cas is an optimization freak and might have an anser for you… i would post this over at puppygames