ingelabs / classpath

GNU Classpath, Essential Libraries for Java
Other
8 stars 3 forks source link

Memory leak in java.text.DecimalFormat #28

Closed ingebot closed 3 months ago

ingebot commented 17 years ago

Note: this issue was migrated automatically using bugzilla2github

Original bug ID: BZ#30977 From: Jeroen Frijters <jeroen@frijters.net> Reported version: 0.93 CC: bug-classpath@gnu.org, xiaoyuanbo@yeah.net

ingebot commented 17 years ago

Comment author: Jeroen Frijters <jeroen@frijters.net>

There's a memory leak in java.text.DecimalFormat. Everytime you call format the attributes ArrayList is grown.

Here's repro test case:

import java.text.*;

class Leak
{
  public static void main(String[] args)
  {
    DecimalFormat d = new DecimalFormat("#.0000");
    for (;;)
      d.format(0.0);
  }
}
ingebot commented 12 years ago

Comment author: Ben Tatham <bentatham@nanometrics.ca>

Created attachment 26464 memory leak fix

Here is a patch for this memory leak in DecimalFormat.

Note that DecimalFormat#formatToCharacterIterator(Object) is (still) not thread-safe and using it across multiple threads it may result in strange behaviour and/or NullPointerExceptions.

Attached file: DecimalFormat.patch (application/octet-stream, 876 bytes) Description: memory leak fix