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

System.gc method doesn't work correctly on Solaris environment.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1
    • Resolution: Duplicate
    • Affects Version/s: 1.1.6
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description

      This is a bug I filed on behalf of NTT Comware.

      (1) Working environments
      OS : Solaris2.5.1 Japanese version
      JRE : JDK1.1.6N (green_threads)
      Window : CDE

      (2) Phenomenon
      Two sources named Frame1.java, StandardMenu.java are attached for reproducing
      this phenomenon. The following show the steps to verify this phenomenon.

      Step1: Compile sources: javac Frame1.java; javac StandardMenu.java.
      Step2: Run Frame1.class as following.
             $jre -cp . Frame1
             Then a frame titled AWTapp appears.
      Step3: Click the [open Child Frame] button on the AWTapp frame.
             Then a child frame appears.
      Step4: Click the [close Child Frame] button on the parent frame.
             Then the child frame disappears.
      Step5: Do Step3-Step4 several times.
      Step6: Click the [call System.gc] button on the parent frame.
             You can see a message "System.gc called" showed on the screen
             which the command jre is executed on.
             Here is the point. If you do this on Windows95, you will see
             other two pieces of message
             "*******Frame1 finalize called*******"
             "*******StandardMenu finalize called*******".
             But on solaris, you cannot.

      Step7: Click the [open Child Frame] on the parent frame
             to display the child frame.
      Step8: Click the [remove Menu ActionListener] on the child frame.
      Step9: Click the [close Child Frame] button on the parent frame
             to close child frame.
      Step10:Repeat Step7-Step9 several times.
      Step11:You can only see a message "Frame1 finalized called".
             But on Windows95, you can see two pieces of message
             "*******Frame1 finalize called*******"
             "*******StandardMenu finalize called*******".
             Although Frame1 is freed, but the StandardMenu is not be freed on Solaris.
             
      Step12:Whatever you firstly click the [remove menubar] button and then close
             the child frame, the phenomena of Step6 and Step11 are the same.

      /** -----Frame1.java------ */

      import java.awt.*;
      import java.awt.event.*;

      public class Frame1 extends Frame implements ActionListener{
          StandardMenu myMenuBar;
          Button closeChildFrameButton = new Button();
          GridLayout gridLayout1 = new GridLayout(5,1);
          Button openChildFrameButton = new Button();
          Button removeMenuAvtionListenerButton = new Button();

          Frame1 child;
          Button gcButton = new Button();
          Button removeMenubarButton = new Button();

          public Frame1() {
              this.setSize(400,400);
              myMenuBar = new StandardMenu();
              this.setMenuBar(myMenuBar);
              myMenuBar.exitMenuItem.addActionListener(this);
              try {
                  jbInit();
              }
              catch (Exception e) {
                  e.printStackTrace();
              }
          }

          //main
          public static void main(String[] args) {
              Frame1 frame11 = new Frame1();
              frame11.setVisible(true);
          }
          //exit menuItem action
          public void actionPerformed(ActionEvent e){
              this.dispose();
              System.exit(0);
          }

          private void jbInit() throws Exception {
              this.setLayout(gridLayout1);
              closeChildFrameButton.setLabel("close Child Frame");
              closeChildFrameButton.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      closeChildFrameButton_actionPerformed(e);
                  }
              });
              openChildFrameButton.setLabel("open Child Frame");
              openChildFrameButton.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      openChildFrameButton_actionPerformed(e);
                  }
              });

              removeMenuAvtionListenerButton.setLabel("remove Menu ActionListener");
              removeMenuAvtionListenerButton.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      removeMenuAvtionListenerButton_actionPerformed(e);
                  }
              });

              gcButton.setLabel("call System.gc()");
              gcButton.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      gcButton_actionPerformed(e);
                  }
              });


              removeMenubarButton.setLabel("remove menubar");
              removeMenubarButton.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      removeMenubarButton_actionPerformed(e);
                  }
              });

              this.add(openChildFrameButton, null);
              this.add(closeChildFrameButton, null);
              closeChildFrameButton.setEnabled(false);
              this.add(removeMenuAvtionListenerButton, null);
              this.add(gcButton, null);
              this.add(removeMenubarButton, null);
          }

          void openChildFrameButton_actionPerformed(ActionEvent e) {
              System.out.println("open child Frame called");
              child = new Frame1();
              child.setVisible(true);
              closeChildFrameButton.setEnabled(true);
              openChildFrameButton.setEnabled(false);
          }

          void closeChildFrameButton_actionPerformed(ActionEvent e) {
              System.out.println("close child Frame called");
              child.dispose();
              child = null;
              closeChildFrameButton.setEnabled(false);
              openChildFrameButton.setEnabled(true);
          }

          void removeMenuAvtionListenerButton_actionPerformed(ActionEvent e) {
              System.out.println("removeActionListener called");
              if(myMenuBar != null){
                  myMenuBar.exitMenuItem.removeActionListener(this);
              }
              removeMenuAvtionListenerButton.setEnabled(false);
          }

          void gcButton_actionPerformed(ActionEvent e) {
              System.out.println("System.gc() called");
              System.gc();
          }

          void removeMenubarButton_actionPerformed(ActionEvent e) {
              System.out.println("remove menubar called");
              if(myMenuBar != null){
                  remove(myMenuBar);
              }
              removeMenubarButton.setEnabled(false);
              myMenuBar = null;
          }
          public void finalize(){
              System.out.println("*********Frame1 finalize called**********");
          }

      }

       /* -------StandardMenu.java------ */
      import java.awt.*;
      import java.awt.event.*;

      public class StandardMenu extends MenuBar {

        Menu FileMenu = new Menu();
        MenuItem exitMenuItem = new MenuItem();


        public StandardMenu() {
          try {
            jbInit();
          }
          catch (Exception e) {
            e.printStackTrace();
          }
        }

        private void jbInit() throws Exception {
          FileMenu.setLabel("File");
          this.add(FileMenu);
          exitMenuItem.setLabel("exit");

          FileMenu.addSeparator();
          FileMenu.add(exitMenuItem);
        }
        public void finalize(){
          System.out.println("*********StandardMenu finalize called*********");
        }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                duke J. Duke (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: