Java Memory Leak
private boolean refreshResponseWindow(MessageObject message) {
this.responsePanel.removeAll();
this.responsePanel.add(message.buildGUI());
this.responsePanel.validate();
message = null;
return true;
}
The problem that is occurring is as I receive more and more messages my Java program's memory usage continues to grow eventually causing it to lock up. I've isolated my memory leak to the code above specifically the add procedure call. I'd assume the removeAll would clear the contents of my panel but it still seems to continue to grow.
Note: The message.buildGUI() returns a JPanel that is displayed on the responsePanel
Follow up:
The BuildGUI code appears as such
public JPanel buildGUI() throws Exception {
JPanel busPanel = new JPanel();
busPanel.setLayout(new GridBagLayout());
busPanel.setPreferredSize(new Dimension(Globals.panelW, Globals.panelH));
busPanel.setMinimumSize(new Dimension(Globals.panelW, Globals.panelH));
final JLabel headingLabel = new JLabel();
headingLabel.setFont(new Font("", Font.PLAIN, 18));
headingLabel.setText(this.name);
final GridBagConstraints gridBagConstraints_heading = new GridBagConstraints();
gridBagConstraints_heading.gridwidth = 2;
gridBagConstraints_heading.gridy = 0;
gridBagConstraints_heading.gridx = 0;
busPanel.add(headingLabel, gridBagConstraints_heading);
//Many more gui components marked as final
return busPanel;
There are no listeners the returned panel is for display purposes only.