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

Use sun.java2d.font.reftype in Font2D ?

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • tbd
    • 9, 10
    • client-libs
    • None
    • 2d
    • linux

      At Google, production users on Linux have trouble with many font creations from InputStreams resulting in many files accumulating in /tmp such as
      +~JF14280372815902140030.tmp

      Those files are retained via a SoftReference. We have experimented with replacing those SoftReferences with WeakReferences in Font2D.java and SunLayoutEngine.java as is done in StrikeCache if sun.java2d.font.reftype is set to "weak", and this seems to mitigate the problem, although of course no one has a real solution to the java resource finalization problem. Is there some way to "close" fonts that we're missing?

      Below is a simple program that demos this:

      import java.awt.Font;
      import java.io.FileInputStream;

      public class FontFileLeak {
          public static void main(String[] args) throws Exception {
              for (;;) {
                  try (FileInputStream fis = new FileInputStream(
                      "/usr/share/fonts/truetype/droid/DroidSerif-Bold.ttf")) {
                      Font thingy = Font.createFont(Font.TRUETYPE_FONT, fis);
                      Font f = thingy.deriveFont(Font.PLAIN, 24);
                  }
              }
          }
      }

      ... and do ls /tmp/*.tmp | wc to "monitor progress"

            prr Philip Race
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: