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

Memory leak happens when awt component create/destroy repeatedly in thread

XMLWordPrintable

    • kestrel
    • sparc
    • solaris_2.6

      (1) Working environments
      OS : Solaris 2.5.1, 2.6, 2.7 Japanese version
      JRE : jdk 1.1.6 fcs, 1.1.8, 1.2.1_03
      Window : CDE

      (2) Phenomenon
      Java application program MemLeak.java, that create and destroy Panel
      in thread on Frame.
      Invoke MemLeak and a few minutes after, The heap in the jre process is
      going on increasing. Check the pmap command during an hour, increasing
      by 1.5 kbytes per second.

      -- MemLeak.java --
      import java.awt.*;

      public class MemLeaks extends Frame implements Runnable {
           MemLeaks() {
                setSize(800, 800);
                setVisible(true);

                new Thread(this).start();
           }

           public void run(){
                while(true){
                     Panel panel = new Panel();
                     add(panel);
                     panel.repaint();

                     try {
                          System.gc();
                          Thread.sleep(100);
                     }
                     catch (InterruptedException e) {}

                     remove(panel);
                }
           }

           public static void main(String[] args){
                new MemLeaks();
           }
      }

            prssunw Prs Prs (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: