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

Simple swing app leaks memory when a display mode change occurs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • 9
    • 6u21, 7, 8u40
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.6.0_21"
      Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
      Java HotSpot(TM) 64-Bit Server VM (build 17.0-b17, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7600]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      I am running with multiple monitors. I reproduced this by having the Java application on the same monitor that I changed the resolution on.

      A DESCRIPTION OF THE PROBLEM :
      When you have a simple swing application running and the display mode changes for any reason the swing application leaks between 5 and 10MB of memory.

      The simplest way to observe this is to switch back and forth between two screen resolutions.

      This is similar to Bug ID 6209673 which is reported to be fixed. The reproduction steps here are slightly simplified to use a change in resolution to trigger the issue.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the attached program (taken from Bug ID 6209673) on Windows.
      2. Maximize the application.
      3. Open task manager and observe the memory being used by the Java application.
      4. Open Display Properties.
      5. Switch the resolution to some other resolution.
      6. Observe the memory increase by between 5 and 10MB.





      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The Java application should not leak memory when the display mode changes.
      ACTUAL -
      The Java application leaked between 5 and 10MB of memory with each display mode change.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Eventually once you leak enough memory to go over the allocated Java heap space you get the typical out of memory error.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Container;
      import java.awt.BorderLayout;
      import javax.swing.JFrame;
      import javax.swing.JLabel;

      public class GraphicLeak
      {
          public static void main(String[] args)
          {
              JFrame frm = new JFrame("Memory leak");
              Container cp = frm.getContentPane();
      cp.add( new JLabel(
                  "<html>Launch Windows Task Manager<br>Maximize the size fo this window.<br>"+
                  "Watch the memory consumption of this process.<br>"+
                  "See that it is in a steady state.<br>"+
                  "Change the resolution of the monitor that the application is running on.<br>"+
                  "Repeat changing the resolution several times.<br>"+
                  "Memory usage of this process appears to jump every time the resolution is changed.<br>"+
                  "If repeated enough times Out-of-memory errors will occur with every reapint.<br>"+
                  "</html>"), BorderLayout.CENTER );

              frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frm.pack();
              frm.setVisible(true);

              while(true)
              {
                  frm.repaint();
                  try { Thread.sleep(100); } catch (InterruptedException e ) {}
              }
          }
      }
      ---------- END SOURCE ----------

            aivanov Alexey Ivanov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: