JDK-4257468 : Memory leakage with JDK1.2.2 (with new Font instruction)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.2.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95,windows_nt
  • CPU: x86
  • Submitted: 1999-07-27
  • Updated: 1999-08-23
  • Resolved: 1999-08-23
Related Reports
Duplicate :  
Description

Name: skT88420			Date: 07/27/99


##
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)

java full version "JDK-1.2.2-W"
##

The following example shows that memory is increasing when typing the button "+". Moreover, appletviewer finishes by crashing when I continue typing the button "+" for a while..

##program java - begin
//<APPLET CODE=TestFont1.class WIDTH=500 HEIGHT=400>
//</APPLET>

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import javax.swing.*;

public class TestFont1 extends Applet
{
	int fontSize=10;
	Font font=new Font("Courier",Font.PLAIN,fontSize);
	Button b1,b2;
	ZDessin zd;
	
	public void init()
	{
		setLayout(new BorderLayout());
		b1=new Button("+");
		b1.addActionListener(new B1AL());
		b2=new Button("-");
		b2.addActionListener(new B2AL());
		add("North",b1);
		add("South",b2);
		zd=new ZDessin();
		add("Center",zd);

		doLayout();
		
		zd.init(this);
	}

	class B1AL implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			font=font.deriveFont(Font.PLAIN,++fontSize);
			zd.dessine();
		}
	}
	
	class B2AL implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			font=font.deriveFont(Font.PLAIN,--fontSize);
			zd.dessine();
		}
	}
}

class ZDessin extends Canvas
{
	Image buf;
	Graphics gBuf;
	String text;
	TestFont1 pere;
	int w,h;

	public void init(TestFont1 app)
	{
		pere=app;
		text="abcd...";
		w=getSize().width;
		h=getSize().height;
		try
		{
			buf=createImage(w,h);
			gBuf=buf.getGraphics();
			System.out.println("ZDessin.init(1): w="+w+" h="+h);
		}
		catch (Exception e)
		{
			System.out.println("ZDessin.init(2): w="+w+" h="+h+"\n"+e);
		}
	
		dessine();
	}
	
	public void paint(Graphics g)
	{
		g.drawImage(buf,0,0,this);
	}

	public void dessine()
	{
		System.gc();
		
		
		gBuf=(Graphics2D)gBuf;
		gBuf.setColor(Color.white);
		gBuf.fillRect(0,0,w,h);
		gBuf.setFont(pere.font);
		gBuf.setColor(Color.black);
		gBuf.drawString(text,20,h-20);
		
		repaint();
		
	}	
}
##program java - end

PS. I'm sorry if this bug is allready reported..!!
I didn't check the bugParad ..
(Review ID: 88450) 
======================================================================

Name: skT88420			Date: 07/28/99


problem: when i grow the font of a text field in IFC (which is 
built on top of AWT), the system crashes after a few steps. i have
to shut down the machine and restart. 
i looked this with the System Monitor: the allocated memory 
reliably grows by about 20 Mega(!)bytes every fews seconds. 
when windows starts running out of memory (which is at about 400M
on my machine) the application crashes with an ugly dialog box. 
most other applications running at the same time also crash.

i tried doing the same thing in Swing, but could not repro it there.
i looked at it with OptimizeIt, and there are no memory leaks 
on the IFC side, so i still think it is a VM issue. also, it works
just fine under java 1.1.x, only java 1.2.x shows the problem (another
hint that it must be the VM).


we have an application that allows the user to change the font size...

1., 2. to reproduce, get netscapes IFC framework and run the follwing
program on windows 95, Java 1.2.2, no other apps running:
/*
	Trivial application - crashes within a couple of steps under Windows 95/JDK 1.2.2
*/

// import netscape IFC package
import netscape.application.*;

public class TrivialApplication extends Application {

	public static void main(String args[]) {
		Application app = new TrivialApplication();
		app.run();
	}
	
	public void init() {
		// set up the main root window
		ExternalWindow drawSpace = new ExternalWindow();

		application().setMainRootView(drawSpace.rootView());
		
		drawSpace.show();
		
		// put up a window with a text view
		InternalWindow win = new InternalWindow(0, 0, 300, 300);
		TextView t = new TextView(0, 0, 300, 300);
		t.setString("Crash");
		win.addSubview(t);		// bug will still happen if this is commented out
								// e.g. it is not a problem with drawing!!
		win.show();	
		// grow the font size from 300 to 400, pause so that gc has a chance to do things
		for (int size=300; size<400; size++) {
			Font font = new Font("Helvetica", Font.PLAIN, size);
			t.setFont(font);
			// System.gc(); // does not help
			try { Thread.sleep(50); }
			catch (java.lang.InterruptedException e) {};
			
		}
		
	}
}

5.
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)
java full version "JDK-1.2.2-W"

6. this happens reliably on all our windows machines 
(different manufacturers). it is not a hardware issue.
(Review ID: 93128)
======================================================================

Comments
EVALUATION Commit to fix in Kestrel (serious memory leak). eric.hawkes@eng 1999-08-03 ###@###.###: This memory leak is not a leak in common sense. Because memory usage looks like some class caches something and sometimes decides that this cache contains too many objects so it clears it. But with font size increasing, memory used by every object in this cache is increasing too. So, with big font this manner causes out of memory error. The test case contains two suspicious classes: Font and WGraphics. In Font I found one cache for fonts but even when i disabled it I had the same behavior of the test. After that I run through the java and c code of WGraphics. But I found nothing that could cause this problem. So, I suggest to recategorize this bug to java2d because the relevant code is mostly 2d by origin, and I think that it will be more effective if somebody from this team will take a look at this bug. This might be an AWT bug, but even in this case person from java2d can find more quickly than me. tdv: So Eric approved the recategarization.. Here is a simplified test case: import java.awt.*; import java.awt.event.*; import java.awt.font.*; public class TestFont1 extends Frame { int fontSize=500; String text="abcd..."; Font font=new Font("Courier",Font.PLAIN,fontSize); public void init() { addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { dispose(); System.exit(0); } }); setSize(500, 400); setVisible(true); } public static void main(String[] args) { TestFont1 tf1 = new TestFont1(); tf1.init(); for (;;) { tf1.font = tf1.font.deriveFont(Font.PLAIN,++tf1.fontSize); Graphics g = tf1.getGraphics(); g.setFont(tf1.font); g.drawString(tf1.text, 20, 400-20); try{ Thread.sleep(500); } catch(InterruptedException ie){} } } } ###@###.### 1999-08-19 for ###@###.### The font cache needs to be smarter when handling large memory chunks - it should be able to dispose off these huge bitmaps and not fill up the memory. parry.kejriwal@eng 1999-08-23
11-06-2004

WORK AROUND Name: skT88420 Date: 07/27/99 dont know? ======================================================================
11-06-2004