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"