JDK-4196138 : The class objects for the closed dialogs have been not deleted.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.7
  • Priority: P2
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_95
  • CPU: x86
  • Submitted: 1998-12-09
  • Updated: 1999-03-12
  • Resolved: 1999-03-12
Related Reports
Relates :  
Description

Name: clC74495			Date: 12/09/98


Carlos.Lucasius@Canada (December 9, 1998):  This bug is from Hitachi,
a licensee.  They claim that without solving this problem they won't be
able to ship their product, which is scheduled for the end of this month.
B.t.w., this bug seems to be strongly related to bugs 4193257, 4193258
(window objects not being garbage collected because of circular references),
which apparently still exist in JDK1.2 (or Java 2 now).

Please look into this issue as soon as possible.


ORIGINAL BUG REPORT FOLLOWS:

The class objects for the closed dialogs have been not deleted.
It causes insufficient memory.

( I don't set the following mark, because I don't know the meaning of the
  number.
	Priority:High. 
	Severity Impact: High.
	Severity Functionality: High.
 )


1. Steps to reproduce.
  (1)Click the main window to display the child dialog.
  (2)Repeat the same operation until display 5 or more child dialog.
  (3)Close all child dialog.
  (4)Check the remaining class object in the memory.
     You will see 2 or 3 class object that had been used by the child
dialog.

  <Problems>
    Why are they remaining? Why are they not deleted completely, even
though the program is calling GC explicitly?
    The remaining objects are preventing the repeat operation, and could
result in insufficient memory easily.
    
    Please let me know the way to delete those object, if any.

  Thanks! 

2. Java Source code.

// main.java
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import ChildDialog.ChildDialog;

public class Main extends Frame implements ActionListener {
        Button okButton = new Button("ok");

        public Main() {
                addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                                setVisible(false);
                                dispose();
                                System.exit(0);
                        }
                });

                setTitle("Main");
                setSize(500, 400);
                add(okButton);
                pack();

                okButton.addActionListener(this);
        }

        public static void main(String args[]) {
                Main m = new Main();
                m.setVisible(true);
        }

        public void actionPerformed(ActionEvent e) {
                if(e.getSource() == okButton) {
                        ChildDialog cd = new ChildDialog(new Frame());
                        cd.setVisible(true);
                }
        }
}


// ChildDialog.java
package ChildDialog;

import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;

public class ChildDialog extends Dialog {
        public ChildDialog(Frame parent) {
                super(parent, "ChildDialog", false);
                setSize(125, 75);

                addWindowListener(new WindowAdapter() {
                        public void windowClosing( WindowEvent e ) {
                                setVisible(false);
                                dispose();
                                java.lang.System.gc();
//                              java.lang.Runtime.gc();
                        }
                });
        }
}
(Review ID: 43471)
======================================================================

Comments
WORK AROUND Name: clC74495 Date: 12/09/98 That's what, I want to know! ====================================================================== Name: dsC76792 Date: 03/04/99 ###@###.### Do not create a new Frame for each Dialog, but create one Frame and then use it as a parent for all dialogs. ======================================================================
11-06-2004

EVALUATION See also 4196661 for JDK1.2 status. [koushi.takahashi@japan 1999-02-04] Name: dsC76792 Date: 03/04/99 ###@###.### In the test case each Dialog is created with a new Frame as a parent. When setVisible(true) is invoked on a Dialog it checks if a peer for its parent exists and if no creates one. Thus, a new Frame peer is created for each Dialog. Then Dialog is disposed and its peer structures are destroyed properly, but its parent Frame peer still exists. It cannot be GC'd because there are two hard references: from WWindowPeer.allWindows and from SunToolkit.peerMap, they will be removed only after the Frame is explicitly disposed of. The same problem exists for java.awt.Window. ====================================================================== This is a Not A Bug; it is a user error. The test program should be changed to dispose the new Frame which is created every time a new Dialog is created. See Comments. david.mendenhall@eng 1999-03-12
12-03-1999