Microsoft KB Archive/244201: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
 
Line 68: Line 68:
== RESOLUTION ==
== RESOLUTION ==


To resolve this problem, update your version of the Microsoft virtual machine (Microsoft VM) to build 3188 (or later). See the "References" section of this article for a link to download the latest Microsoft VM.
To resolve this problem, update your version of the Microsoft virtual machine (Microsoft VM) to build 3188 (or later). See the "References" section of this article for a link to download the latest Microsoft VM.


</div>
</div>
Line 100: Line 100:


     public GDILeakTest() {
     public GDILeakTest() {
         super(&quot;GDI leak Test&quot;);
         super("GDI leak Test");
         canvas = new PrintCanvas();
         canvas = new PrintCanvas();
         add(&quot;Center&quot;, canvas);
         add("Center", canvas);


         Button b = new Button(&quot;Print&quot;);
         Button b = new Button("Print");
         b.setActionCommand(&quot;print&quot;);
         b.setActionCommand("print");
     b.addActionListener( new ActionListener(){
     b.addActionListener( new ActionListener(){
                 public void actionPerformed(ActionEvent e){
                 public void actionPerformed(ActionEvent e){
Line 111: Line 111:
                 }
                 }
             });
             });
         this.add(&quot;South&quot;, b);
         this.add("South", b);


     this.addWindowListener( new WindowAdapter(){
     this.addWindowListener( new WindowAdapter(){
Line 129: Line 129:
     private void buttonActionHandler(ActionEvent e){
     private void buttonActionHandler(ActionEvent e){
     String cmd = e.getActionCommand();
     String cmd = e.getActionCommand();
     if (cmd.equals(&quot;print&quot;)) {
     if (cmd.equals("print")) {
         PrintJob pjob = getToolkit().getPrintJob(this,
         PrintJob pjob = getToolkit().getPrintJob(this,
                         &quot;GDI Leak Test&quot;, null);
                         "GDI Leak Test", null);
         if (pjob != null) {
         if (pjob != null) {
         Graphics pg = pjob.getGraphics();
         Graphics pg = pjob.getGraphics();
Line 157: Line 157:


     public void paint(Graphics g) {
     public void paint(Graphics g) {
         Font font = new Font(&quot;Courier&quot;, Font.BOLD, 11);
         Font font = new Font("Courier", Font.BOLD, 11);
         g.setFont(font);
         g.setFont(font);
         g.setColor(Color.black);
         g.setColor(Color.black);
         g.drawString(&quot;This is a test page&quot;, 10, 50);
         g.drawString("This is a test page", 10, 50);
         g.drawString(&quot;Print this page number of times&quot;, 10, 70);
         g.drawString("Print this page number of times", 10, 70);
         g.drawString(&quot;Watch the resource meter&quot;, 10, 90);
         g.drawString("Watch the resource meter", 10, 90);
     }
     }
}
}

Latest revision as of 13:49, 21 July 2020

Article ID: 244201

Article Last Modified on 6/14/2006



APPLIES TO

  • Microsoft Java Virtual Machine, when used with:
    • Microsoft Windows NT 4.0
    • Microsoft Windows 95
    • Microsoft Windows 98 Standard Edition



This article was previously published under Q244201

SYMPTOMS

If you use PrintJob (through getToolkit().getPrintJob) for printing multiple times through Java, this results in depletion of Graphics Device Interface (GDI) resources. If the applet that is doing the printing is hosted in a browser, it will eventually cause the browser to stop responding.

CAUSE

The device context is not being deleted in Graphics.dispose().

RESOLUTION

To resolve this problem, update your version of the Microsoft virtual machine (Microsoft VM) to build 3188 (or later). See the "References" section of this article for a link to download the latest Microsoft VM.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Microsoft VM build 3188 and later.

This problem was corrected in Windows 2000 Service Pack 1.


MORE INFORMATION

Steps to Reproduce Behavior

You can follow this procedure to reproduce the problem behavior:

  1. On a Windows 98-based computer with Microsoft VM version 3186 or earlier, create a file GDILeakTest.java with the following code:

    import java.awt.*;
    import java.awt.event.*;
    
    public class GDILeakTest extends Frame {
    
        PrintCanvas canvas;
    
        public GDILeakTest() {
            super("GDI leak Test");
            canvas = new PrintCanvas();
            add("Center", canvas);
    
            Button b = new Button("Print");
            b.setActionCommand("print");
        b.addActionListener( new ActionListener(){
                    public void actionPerformed(ActionEvent e){
                        buttonActionHandler(e);
                    }
                });
            this.add("South", b);
    
        this.addWindowListener( new WindowAdapter(){
                    public void windowClosing(WindowEvent e){
                        close();
                    }
                });
            
            this.pack();
        }
    
        public void close()
        {
        System.exit(0);
        }
        
        private void buttonActionHandler(ActionEvent e){
        String cmd = e.getActionCommand();
        if (cmd.equals("print")) {
            PrintJob pjob = getToolkit().getPrintJob(this,
                            "GDI Leak Test", null);
            if (pjob != null) {
            Graphics pg = pjob.getGraphics();
    
            if (pg != null) {
               canvas.printAll(pg);
               pg.dispose();
            }
            pjob.end();
            }
        }
        }
            
        public static void main(String args[]) {
            GDILeakTest test = new GDILeakTest();
            test.show();
        }
    }
    
    class PrintCanvas extends Canvas {
    
        public Dimension getPreferredSize() {
            return new Dimension(400, 200);
        }
    
        public void paint(Graphics g) {
            Font font = new Font("Courier", Font.BOLD, 11);
            g.setFont(font);
            g.setColor(Color.black);
            g.drawString("This is a test page", 10, 50);
            g.drawString("Print this page number of times", 10, 70);
            g.drawString("Watch the resource meter", 10, 90);
        }
    }
    
                        
  2. Use the following command to compile GDILeakTest.java:

    jvc GDILeakTest.java

  3. Run the generated GDILeakTest.class using:

    jview GDILeakTest.class

    This will cause a frame dialog box to appear with a Print button.
  4. Open the Resource Meter tool in Windows 98 (from the Start menu, point to Programs, point to Accessories, point to System Tools, and click Resource Meter). Click the Print button to print a test page, and each print will show a decrease in the GDI and system resources. After a number of repeated prints, the GDI resources will be exhausted and the system will become unresponsive or come to a halt.


REFERENCES

The latest Microsoft VM is available for download at the following Web site:

For additional information about the latest service pack for Windows 2000, click the article number below to view the article in the Microsoft Knowledge Base:

260910 How to Obtain the Latest Windows 2000 Service Pack


For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:



Keywords: kbbug kbfix kbjavavm33xxfix kbqfe kbjavavm31xxfix kbfaq KB244201