Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4267819

Memory leak deriving transformed font

XMLWordPrintable

    • 2d
    • kestrel
    • x86
    • windows_nt



      Name: rlT66838 Date: 09/01/99


      Deriving a transformed font causes a large memory leak.
      An application that must derive many fonts crashes with an
      Out of Memory exception.
      Sample code follows:

      import java.awt.geom.*;
      import java.awt.*;

      public class Leak {

        static Runtime runtime = Runtime.getRuntime();
        static Font base = new Font("Arial", Font.PLAIN, 12);
        static AffineTransform at = new AffineTransform(0.2, 0.0, 0.0, 0.2, 5.0, 5.0);
        static long start = 0;
        static long end = 0;

        public static void mem(String msg) {
          runtime.gc();
          end = runtime.totalMemory() - runtime.freeMemory();
          if (start == 0) {
            System.out.println(msg + ": Memory used = " + end);
          } else {
            System.out.println(msg + ": Memory used = " + end +
                                     " change = " + (end - start));
          }
          start = end;
        }

        public static void main(String[] args) {
          base.deriveFont(at);
          mem("Start ");
          for (int i = 0; i < 10000; i++) {
            base.deriveFont(at);
          }
          mem("Derive font ");
        }
      }
      (Review ID: 94581)
      ======================================================================

      I found this bug in Solaris as well:

      figjam:src/java/bhpit 274$ uname -a
      SunOS figjam 5.7 Generic sun4u sparc SUNW,Ultra-5_10
      figjam:src/java/bhpit 276$ java -version
      java version "1.2.2"
      Classic VM (build JDK-1.2.2-W, native threads, sunwjit)

            dougfelt Doug Felt
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: