JDK-7074159 : run out of memory
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6u26
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2008
  • CPU: x86
  • Submitted: 2011-08-02
  • Updated: 2020-04-07
  • Resolved: 2020-04-07
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version 1.6.0_22

ADDITIONAL OS VERSION INFORMATION :
Windows Server 2008 R2 Enterprise

A DESCRIPTION OF THE PROBLEM :
I have large amount fonts which are created by calling Font.createFont(). For each server running cycle, I can load more than 10000 different fonts. It causes system run out of memory.

I create a simply test case to illustrate the problem, which repeat loading arial.ttf and rendering some text. I profiled this code by using NetBean profile tools. It doesn't show there is memory leak and memory usage is under my VM setting. However, in windows system monitor, the memory usage of JVM keeps growing until run out of memory.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
running my test code

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The memory usage of JVM should be stable after certain period.
ACTUAL -
Memory keeps growing until run out of memory

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;

public class TestTrueTypeFontLoad
{
  public static void main(String args[])
  {
    try
    {
      for(int i=0; i<50000; i++)
      {
        Font afont = Font.createFont(Font.PLAIN, new File("arial.ttf"));
        BufferedImage bimg = new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB);
        Graphics2D gs = bimg.createGraphics();
        gs.setFont(afont.deriveFont(Font.PLAIN, new AffineTransform(10, 0, 0, 10, 10, 10)));
        gs.drawString("This is font load test", 0, 0);
        gs.setFont(afont.deriveFont(Font.PLAIN, new AffineTransform(12, 0, 0, 12, 10, 10)));
        gs.drawString("$%^**&()^^%$#^&***)(", 0, 0);
        gs.setFont(afont.deriveFont(Font.PLAIN, new AffineTransform(14, 0, 0, 14, 10, 10)));
        gs.drawString("F%^.wqiwexhuam,ox,251719280-+", 0, 0);
      }
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I haven't been able to find a work around