public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcj/16134] New: Memory leak in String.getBytes()
@ 2004-06-22 10:23 hannes at helma dot at
  2004-06-22 13:04 ` [Bug libgcj/16134] " hannes at helma dot at
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: hannes at helma dot at @ 2004-06-22 10:23 UTC (permalink / raw)
  To: java-prs

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
                "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".getBytes();
                // using our own bogus implementation fixes the problem
                // getBytes("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException x) {
                System.exit(0);
            }
        }
    }

    // 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


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16134


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-07-10  0:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-22 10:23 [Bug libgcj/16134] New: Memory leak in String.getBytes() hannes at helma dot at
2004-06-22 13:04 ` [Bug libgcj/16134] " hannes at helma dot at
2004-06-22 13:54 ` hannes at helma dot at
2004-06-22 16:51 ` mckinlay at redhat dot com
2004-06-22 17:21 ` mckinlay at redhat dot com
2004-06-22 17:23 ` cvs-commit at gcc dot gnu dot org
2004-06-22 18:22 ` mckinlay at redhat dot com
2004-07-10  0:37 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).