Re: buff = new StringBuffer(10000); buff.toString(); Will GC be complete here?

From: Chris Uppal (chris.uppal_at_metagnostic.REMOVE-THIS.org)
Date: 02/18/04


Date: Wed, 18 Feb 2004 12:03:30 -0000

Chris Smith wrote:

> There are three objects involved for each iteration of the loop in main:
> a StringBuffer, a String, and a (internal) char[] which is used to hold
> the real character data.

Well, whatdya know ?

I was about to reply that I thought there must be at least four. The
StringBuffer, its large internal char[] array, the String object, and its small
internal char[] array. Since the String is not allowed to change when the
contents of the StringBuffer are changed, it is not possible for the two
objects to share a common char[] buffer.

But it turns out that the Sun implementation *does* share the buffer, but marks
it copy-on-write in the StringBuffer object.

Live and learn...

Thanks.

    -- chris



Relevant Pages

  • Re: buff = new StringBuffer(10000); buff.toString(); Will GC be complete here?
    ... StringBuffer, its large internal char[] array, the String object, and its small ... But it turns out that the Sun implementation *does* share the buffer, ...
    (comp.lang.java.programmer)
  • Re: what is the use of capacity method in StringBuffer
    ... to allocate a new internal buffer array. ... While entirely true, it doesn't explain, why any programmer ... of chars to the stringbuffer, you have the option of allocating ...
    (comp.lang.java.programmer)
  • Re: End of String
    ... Jeffrey Schwab ha escrito: ... the buffer, but the amount of valid content it contains. ... Then you'd better use StringBuffer instead: ... and C uses \u0000 to delimit the end of Strings. ...
    (comp.lang.java.programmer)
  • Re: HTML in Java
    ... * the initial File from some buffer or something, ... JFileChooser keuze1 = new JFileChooser; ... File selectedFile = null; ... StringBuffer stringBuffer = new StringBuffer; ...
    (comp.lang.java.gui)
  • Re: Name not displaying in program
    ... buffer = new StringBuffer(FirstName); ... Roedy Green Canadian Mind Products ...
    (comp.lang.java.help)