[Bug libgcj/16134] New: Memory leak in String.getBytes()

hannes at helma dot at gcc-bugzilla@gcc.gnu.org
Tue Jun 22 10:23:00 GMT 2004

Looks like there is a memory leak in java.lang.String.getBytes() in libgcj
3.3.3. The following code keeps growing continuously in memory:

// Test code for String.getBytes() memory leak
public class StringBytesLeak {

    public static void main(String[] args) {
        while (true) {
            for (int i=0; i<10000; i++) {
                // leaks memory
                // using our own bogus implementation fixes the problem
                // getBytes("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            try {
            } catch (InterruptedException x) {

    // simplistic implementation of String.getBytes() that doesn't leak
    static byte[] getBytes(String str) {
        int length = str.length();
        byte[] bytes = new byte[length];
        for (int i=0; i<length; i++) 
            bytes[i] = (byte) str.charAt(i);
        return bytes;


           Summary: Memory leak in String.getBytes()
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libgcj
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hannes at helma dot at
                CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
                    dot org
 GCC build triplet: i686-suse-linux
  GCC host triplet: i686-suse-linux
GCC target triplet: i686-suse-linux


More information about the Java-prs mailing list