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

Windows GDI leak in the Java plugin version 1.3 and 1.4

XMLWordPrintable

    • 06
    • x86
    • windows_nt

      Running an applet hosted in the java plugin within Internet Explorer 5.5 SP2. Each time IE is told to print the applet, more and more GDI resources (Device Contexts (DC's), Regions) are consumed - never released until the process (IE) is terminated. This can be verified under Windows2000's Task Manager by including "GDI Objects" to view for a process and watching it climb, or under Windows NT by running a 3rd party application such as NTObjects (by www.smidgeonsoft.com), refreshing its snapshot of resources after every print. If the applet is complex enough I believe the resources are consumed more rapidly, and if performed over a long enough time, all Windows resources are consumed, causing the display of windows/icons/start menu/etc to fail altogether.

      The GDI resource leak occurs in Java Plugin 1.3.1_01, 1.3.1_02, and 1.4. Although in 1.4 with IE, only the DC's increase. I also tested Netscape
      4.77. A leak still occurs with Netscape, but only the Region is increasing
      and not the DC's. The problem does not occur with appletviewer.

      I have supplied a simple applet and instructions to reproduce the
      problem below.

      1) On a Windows NT 4.0 box, compile TestApplet.java (attached), and place TestWithPlugin.html (attached) and TestWithoutPlugin.html (attached) in the same directory as the compiled TestApplet*.class files.
      2) Download NTObjects for Windows NT/2000 from http://www.smidgeonsoft.com, extract it (NTObInst.exe from NTObInst.zip), and run NTObInst.exe to install it.
      3) Launch TestWithoutPlugin.html in Internet Explorer 5.5 (other versions may suffice as well). This runs the applet WITHOUT the plugin - all Microsoft here. This is to demonstrate that there is NOT a leak without using the plugin.
      4) Launch NTObjects (it will be on your "Start" menu).
      5) In NTObjects' left window pane, find the "(path)\iexplore.exe" process. If there are more than one of these, close all other Internet Explorer windows first and press F5 to refresh (within NTObjects) until there is just one instance. This is the Internet Explorer process. Click the "+" to expand the treeview, then also expand the "GDI Objects". Take note of the "Device Context", "Region", etc items showing how many of these items are allocated within the process.
      6) From Internet Explorer, print the page. Since you will be doing this many times, I suggest creating a "File" print device rather than wasting paper.
      7) Back to NTObjects, refresh its object list by pressing F5.
      8) Repeat steps 5 thru 7 a few times (5 to 10). Note that although the GDI objects probably increased the first time printed (because it allocated some things using for printing and is keeping them around for subsequent print jobs), but after that did not keep increasing. Evidence that it is not leaking.
      9) Close Internet Explorer.
      10) Now launch TestWithPlugin.html in Internet Explorer. This runs the applet WITH the plugin. This is to demonstrate that there IS a leak using the plugin.
      11) again repeat steps 5 thru 7 a few times (5 to 10). Note that this time the GDI objects, most notably the "Device Context" and "Region" items, keep increasing at each print. The "Device Context" item usually increases by one each time, and the "Region" items increase by 16 or so each time.

      Test applet
      ---------------
      import java.awt.*;
      import java.applet.*;

      public class TestApplet extends Applet
      {
      public void init()
      {
      setLayout(null);
      setSize(426,266);
      TestButton.setLabel("Do-nothing Button");
      add(TestButton);
      TestButton.setBackground(java.awt.Color.lightGray);
      TestButton.setBounds(72,72,105,40);
      SymAction lSymAction = new SymAction();
      TestButton.addActionListener(lSymAction);
      }

      java.awt.Button TestButton = new java.awt.Button();

      class SymAction implements java.awt.event.ActionListener
      {
      public void actionPerformed(java.awt.event.ActionEvent event)
      {
      Object object = event.getSource();
      if (object == TestButton)
      TestButton_ActionPerformed(event);
      }
      }

      void TestButton_ActionPerformed(java.awt.event.ActionEvent event)
      {
      }
      }
      --------
      Test with plug in
      <HTML>
        <HEAD><TITLE>Autogenerated HTML</TITLE></HEAD>
        <BODY>
          <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = 402 HEIGHT = 222 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
            <PARAM NAME = CODE VALUE = "TestApplet.class" >
            <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
            <PARAM NAME="scriptable" VALUE="false">
          </OBJECT>
        </BODY>
      </HTML>
      ---------
      Test without plugin
      <HTML>
      <HEAD>
      <TITLE>Autogenerated HTML</TITLE>
      </HEAD>
      <BODY>
      <APPLET CODE="TestApplet.class" WIDTH=426 HEIGHT=266></APPLET>
      </BODY>
      </HTML>

            ccheung Calvin Cheung
            mhmccart Mary Mccarthy
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: