-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.2.2
-
x86
-
windows_nt
Name: skT45625 Date: 04/18/2000
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)
We have an application which is made up of a number of forms
residing in a CardLayout. Only the visible form has a data
model assigned to it. The model is dropped when a form
is hidden (i.e. when the CardLayout shows another form).
When studying the "Mem Usage" column in WindowsNT's Task Manager
(while changing CardLayout pages in the application), it is obvious
that the application stacks up memory that isn't released back to
the system. The excess memory is, however, released if you minimize
(iconify) and then normalize (deiconify) the application's frame.
The supplied test program creates a JFrame with a CardLayout containing
several JTables. The button at the bottom will cause the current JTable to
drop its data model (or rather create a new empty one) and then display
the next page with a JTable with a fresh model.
Change page a couple of times, and then minimize and normalize the window.
Watch what happens to "Mem Usage" in the Task Manager.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class MinimizeTest extends JFrame {
private final static int MAX_PAGES = 100;
private final static int MAX_ROWS = 200;
private final static int MAX_COLUMNS = 10;
JPanel cardPanel = new JPanel();
CardLayout cardLayout = new CardLayout();
public MinimizeTest () {
super("Minimize Test");
cardPanel.setLayout(cardLayout);
for (int p = 0; p < MAX_PAGES; p++) {
cardPanel.add(createPage(p), String.valueOf(p));
}//end for
JButton btnNext = new JButton("Next Page");
btnNext.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
cardLayout.next(cardPanel);
}//end actionPerformed
});//end ActionListener
getContentPane().setLayout(new BorderLayout());
getContentPane().add(cardPanel, BorderLayout.CENTER);
getContentPane().add(btnNext, BorderLayout.SOUTH);
cardLayout.first(cardPanel);
}//end constructor
JScrollPane createPage (final int page) {
JScrollPane scrollPane = new JScrollPane(createTable(page));
scrollPane.addComponentListener(new ComponentAdapter() {
// A table will drop its model when it is hidden
public void componentHidden(ComponentEvent evt) {
JScrollPane sp = (JScrollPane)(evt.getSource());
JTable table = (JTable)(sp.getViewport().getView());
table.setModel(new DefaultTableModel()); //empty model
System.out.println("\n" + table.toString());
}//end componentHidden
// Table will get a new model when it is shown
public void componentShown(ComponentEvent evt) {
JScrollPane sp = (JScrollPane)(evt.getSource());
JTable table = (JTable)(sp.getViewport().getView());
table.setModel(createTableModel(page));
System.out.println(table.toString());
}//end componentShown
});
return scrollPane;
}//end createPage
JTable createTable (final int page) {
JTable table = new JTable() {
public String toString() {
return "Table at page " + page
+ ", model size is "
+ (getModel() == null ? 0 : getModel().getRowCount())
+ " rows";
}//end toString
};//end JTable
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
return table;
}//end createTable
TableModel createTableModel (final int page) {
return new DefaultTableModel(MAX_ROWS, MAX_COLUMNS) {
public Object getValueAt(int row, int column) {
return "Page " + page
+ " Row " + row
+ " Col " + column;
}//end getValueAt
};//end DefaultTableModel
}//end createTableModel
public static void main (String[] args) {
MinimizeTest mt = new MinimizeTest();
mt.setDefaultCloseOperation(3);
mt.pack();
mt.setVisible(true);
}//end main
}//end class MinimizeTest
(Review ID: 103839)
======================================================================
- relates to
-
JDK-4412569 Memory spike until Frame minimized
- Closed