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

1.2 only: Serious memory leak in Frame creation and deletion in AWT

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description


      ingrid.yao@Eng 2000-02-29

      If HP's customer run on 1.1.x and 1.2.x, they show a serious memory
      leak in Frame creation and deletion happen. Attached is a program
      that shows the leak and more detail info:

      The increase in size is about 0.2MB per 100 frame creation/
      deletions which gives ~ 2000 bytes per Frame creation/deletion.

      Here are some clues about the leak :-

      > 1. The amount of the leak got twice when they printed Kanji on
      > buttons, created Kanji Font instance each time the windows were
      > created and designted fonts other than the default font.
      >
      > 2. The amount of the leak got eight times when they use Choice instead
      > of Button.
      >
      > 3. The amount of the leak got four times when they use TextField instead
      > of Button.
      >
      > 4. The results were almost the same when they used Dialog instead of
      > Frame.
      >

      With the help of a tool that tracks malloc and free they were able to
      narrow down the leaked memory to the following function :-

      Java_sun_awt_motif_MComponentPeer_setFont

      surprised to see the following comment in the awt_Component.c :-
       
      /*Leak baby leak! */
          fdata = awtJNI_GetFontData(env, f, &err);
          if (fdata == 0) {
              JNU_ThrowInternalError(env, err);
              AWT_UNLOCK();
              return;
          }


      The fdata is practically never getting freed. The only
      place it can be freed is in the fonts dispose method and
      it is never getting called, with the Buta testcase. This
      explains the constant rate of the leak.

      The defect is quite urgent and HP's customer is waiting
      for a fix to make their release.

      Test case
      ===========
      import java.awt.*;
      import java.awt.Event.*;

      public class Buta extends Frame
      {
      protected Panel centerPanel = new Panel();
      protected GridLayout gridLayout = new GridLayout( 6, 6, 5, 5 );
      protected Button btn[] = new Button[36];

      private Buta ()
      {
      super ();
      centerPanel.setLayout(gridLayout);
      for ( int i = 0 ; i < btn.length ; i++ )
      {
      btn[i] = new Button("ABCD");
      centerPanel.add(btn[i]);
      }
      add(centerPanel, BorderLayout.CENTER);
      pack();
      setVisible(true);
      }

      public void closeWindow()
      {
      setVisible(false);

      dispose();
      for ( int i = btn.length - 1 ; i >= 0 ; i-- )
      {
      gridLayout.removeLayoutComponent(btn[i]); // add by k

      btn[i] = null;
      }
      centerPanel.removeAll(); // add by k
      centerPanel.removeNotify(); // add by k

      centerPanel = null;
      gridLayout = null;
      btn = null;
      try {
      // remove by ki.
      // reason: it isn't ensure to run this method at just this time.
      // super.finalize ();
      }
      catch ( java.lang.Throwable ex ) {
      System.out.println("2222222222222");
      }
      try {
      // remove by k.
      // reason: it isn't ensure to run this method at just this time.
      // finalize();
      }
      catch ( java.lang.Throwable ex ) {
      System.out.println("1111111111111");
      }
      finally {
      System.gc();
      }
      }


      /******* test 1 ************/
      public static void main(String[] args)
      {
      System.out.println("Key In Start");
      try {
      System.in.read ();
      }
      catch (Exception e) {
      }

      int i, j;
      Buta buta[];

      buta = new Buta[100];

      // for ( j = 0 ; j < 10 ; j++ )
      j = 0;
      while(true)
      {
      System.out.println("Key In NEW") ;
      for ( i = 0 ; i < buta.length ; i++ )
      {
      System.out.print("j = " + j + " ");
      System.out.println("i = " + i );
      buta[i] = new Buta();
      }

      System.out.println("Key In dispose" );

      for ( i = 0 ; i < buta.length ; i++ )
      {
      System.out.print( "j = " + j + " " );
      System.out.println( "i = " + i );
      buta[i].closeWindow ();
      // buta[i] = null;
                              try
                              {
                                  Thread.sleep(30);
                              }
                              catch(InterruptedException e)
                              {}
      System.gc(); // add by k
      }

      System.gc();
      System.gc();
      j++;
      }

      }
      }

      // System.exit ( 0 );
      /*********
      try {
      System.in.read();
      }
      catch (Exception e) {
      }
      *********/

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ehawkessunw Eric Hawkes (Inactive)
              Reporter:
              tyao Ting-Yun Ingrid Yao (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: