1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-13 17:00:09 -09:00

Some changes to reduce memory leaks.

This commit is contained in:
LevelX2 2014-01-31 15:08:40 +01:00
parent e2c0e211ef
commit 30ddcaf99b
12 changed files with 139 additions and 83 deletions

View file

@ -1,5 +1,5 @@
#default levels #default levels
log4j.rootLogger=debug, console, logfile log4j.rootLogger=info, console, logfile
#console log #console log
log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console=org.apache.log4j.ConsoleAppender

View file

@ -553,7 +553,6 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} }
public static void deactivate(MagePane frame) { public static void deactivate(MagePane frame) {
//MusicPlayer.stopBGM();
frame.setVisible(false); frame.setVisible(false);
MagePane topmost = getTopMost(frame); MagePane topmost = getTopMost(frame);
if (activeFrame != frame) { if (activeFrame != frame) {
@ -623,16 +622,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
public void showDraft(UUID draftId) { public void showDraft(UUID draftId) {
try { try {
DraftPane draftPane = null; DraftPane draftPane = new DraftPane();
for(Component component :desktopPane.getComponents()) { desktopPane.add(draftPane, JLayeredPane.DEFAULT_LAYER);
if (component instanceof DraftPane) {
draftPane = (DraftPane) component;
}
}
if (draftPane == null) {
draftPane = new DraftPane();
desktopPane.add(draftPane, JLayeredPane.DEFAULT_LAYER);
}
draftPane.setMaximum(true); draftPane.setMaximum(true);
draftPane.setVisible(true); draftPane.setVisible(true);
draftPane.showDraft(draftId); draftPane.showDraft(draftId);
@ -640,7 +631,17 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} catch (PropertyVetoException ex) { } catch (PropertyVetoException ex) {
} }
} }
public void endDraft(UUID draftId) {
// inform all open draft panes about
for (JInternalFrame window : desktopPane.getAllFramesInLayer(JLayeredPane.DEFAULT_LAYER)) {
if (window instanceof DraftPane) {
DraftPane draftPane = (DraftPane) window;
draftPane.hideDraft();
}
}
}
public void showTournament(UUID tournamentId) { public void showTournament(UUID tournamentId) {
try { try {
for(Component component :desktopPane.getComponents()) { for(Component component :desktopPane.getComponents()) {
@ -992,6 +993,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} else { } else {
name = "Deck Editor"; name = "Deck Editor";
} }
// use already open editor
JInternalFrame[] windows = desktopPane.getAllFramesInLayer(JLayeredPane.DEFAULT_LAYER); JInternalFrame[] windows = desktopPane.getAllFramesInLayer(JLayeredPane.DEFAULT_LAYER);
for (JInternalFrame window : windows) { for (JInternalFrame window : windows) {
if (window instanceof DeckEditorPane && window.getTitle().equals(name)) { if (window instanceof DeckEditorPane && window.getTitle().equals(name)) {
@ -1000,6 +1002,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} }
} }
} }
try { try {
DeckEditorPane deckEditorPane = new DeckEditorPane(); DeckEditorPane deckEditorPane = new DeckEditorPane();
desktopPane.add(deckEditorPane, JLayeredPane.DEFAULT_LAYER); desktopPane.add(deckEditorPane, JLayeredPane.DEFAULT_LAYER);
@ -1156,6 +1159,14 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
return drafts.get(draftId); return drafts.get(draftId);
} }
public static void removeDraft(UUID draftId) {
DraftPanel draftPanel = drafts.get(draftId);
if (draftPanel != null) {
drafts.remove(draftId);
draftPanel.hideDraft();
}
}
public static void addDraft(UUID draftId, DraftPanel draftPanel) { public static void addDraft(UUID draftId, DraftPanel draftPanel) {
drafts.put(draftId, draftPanel); drafts.put(draftId, draftPanel);
} }

View file

@ -28,6 +28,7 @@
package mage.client.dialog; package mage.client.dialog;
import java.awt.KeyboardFocusManager;
import mage.utils.MageVersion; import mage.utils.MageVersion;
/* /*
@ -48,7 +49,7 @@ public class AboutDialog extends MageDialog {
public AboutDialog() { public AboutDialog() {
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
initComponents(); initComponents();
this.modal = true; this.modal = false;
} }
public void showDialog(MageVersion version) { public void showDialog(MageVersion version) {
@ -131,8 +132,6 @@ public class AboutDialog extends MageDialog {
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
this.removeDialog(); this.removeDialog();
}//GEN-LAST:event_btnOkActionPerformed }//GEN-LAST:event_btnOkActionPerformed

View file

@ -1,37 +1,36 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
/* /*
* MageDialog.java * MageDialog.java
* *
* Created on 15-Dec-2009, 10:28:27 PM * Created on 15-Dec-2009, 10:28:27 PM
*/ */
package mage.client.dialog; package mage.client.dialog;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -48,13 +47,15 @@ import mage.client.MageFrame;
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class MageDialog extends javax.swing.JInternalFrame { public class MageDialog extends javax.swing.JInternalFrame {
private static final Logger logger = Logger.getLogger(MageDialog.class); private static final Logger logger = Logger.getLogger(MageDialog.class);
protected boolean modal = false; protected boolean modal = false;
/** Creates new form MageDialog */ /**
* Creates new form MageDialog
*/
public MageDialog() { public MageDialog() {
initComponents(); initComponents();
} }
@ -163,35 +164,47 @@ import mage.client.MageFrame;
} }
public void removeDialog() { public void removeDialog() {
setVisible(false); // avoid memory leak of javax.swing.plaf.nimbus.NimbusStyle$CacheKey
MageFrame.getDesktop().remove(this); KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
this.ui.uninstallUI(this); //this.setVisible(false);
this.dispose(); // important to set close before removing the JInternalFrame to avoid memory leaks (http://bugs.java.com/view_bug.do?bug_id=7163808)
try { try {
this.setSelected(false); this.setClosed(true);
} catch (PropertyVetoException ex) { } catch (PropertyVetoException ex) {
java.util.logging.Logger.getLogger(MageDialog.class.getName()).log(Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(MageDialog.class.getName()).log(Level.SEVERE, "setClosed(false) failed", ex);
}
MageFrame.getDesktop().remove(this);
// this.ui.uninstallUI(this);
logger.warn("Remove Dialog " + this.getClass().getName() + " Components left: " + this.getComponentCount());
for (Component comp : this.getComponents()) {
logger.warn("Existing Component: " + comp.getClass().getName());
} }
} }
/**
* Used to set a tooltip text on icon and titel bar
*
* used in {@link ExileZoneDialog} and {@link ShowCardsDialog}
*
* @param text
*/
public void setTitelBarToolTip(final String text) { public void setTitelBarToolTip(final String text) {
desktopIcon.setToolTipText(text); //tooltip on icon desktopIcon.setToolTipText(text); //tooltip on icon
Component[] children = getComponents(); Component[] children = getComponents();
if (children != null) { if (children != null) {
for(int i = 0; i < children.length; i++) { for (Component children1 : children) {
if (children[i].getClass().getName().equalsIgnoreCase( if (children1.getClass().getName().equalsIgnoreCase("javax.swing.plaf.synth.SynthInternalFrameTitlePane")) {
"javax.swing.plaf.synth.SynthInternalFrameTitlePane")){ ((JComponent) children1).setToolTipText(text); //tooltip on title bar
((JComponent)children[i]).setToolTipText(text);//tooltip on title bar
break; break;
} }
} }
} }
} }
/** This method is called from within the constructor to /**
* initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is * WARNING: Do NOT modify this code. The content of this method is always
* always regenerated by the Form Editor. * regenerated by the Form Editor.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
@ -214,5 +227,4 @@ import mage.client.MageFrame;
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }

View file

@ -39,9 +39,11 @@ import mage.client.plugins.impl.Plugins;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.beans.PropertyVetoException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import mage.client.MageFrame;
/** /**
* *
@ -73,9 +75,16 @@ public class DraftPane extends MagePane {
this.setTitle("Draft - " + draftId); this.setTitle("Draft - " + draftId);
this.draftPanel1.showDraft(draftId); this.draftPanel1.showDraft(draftId);
} }
public void hideDraft() { public void hideDraft() {
draftPanel1.hideDraft(); KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
try {
this.setClosed(true);
} catch (PropertyVetoException ex) {
}
this.hideFrame();
MageFrame.getDesktop().remove(this);
} }
/** This method is called from within the constructor to /** This method is called from within the constructor to

View file

@ -64,7 +64,7 @@ public class DraftPanel extends javax.swing.JPanel {
private int timeout; private int timeout;
private boolean picked; private boolean picked;
private static CardsView emptyView = new CardsView(); private static final CardsView emptyView = new CardsView();
/** Creates new form DraftPanel */ /** Creates new form DraftPanel */
public DraftPanel() { public DraftPanel() {
@ -162,7 +162,7 @@ public class DraftPanel extends javax.swing.JPanel {
c = c.getParent(); c = c.getParent();
} }
if (c != null) { if (c != null) {
((DraftPane)c).hideFrame(); ((DraftPane)c).hideDraft();
} }
} }

View file

@ -86,7 +86,7 @@ public class FeedbackPanel extends javax.swing.JPanel {
} }
public void getFeedback(FeedbackMode mode, String message, boolean special, Map<String, Serializable> options, int messageId) { public void getFeedback(FeedbackMode mode, String message, boolean special, Map<String, Serializable> options, int messageId) {
logger.info("text: " + message); logger.debug("text: " + message);
synchronized (this) { synchronized (this) {
if (messageId < this.lastMessageId) { if (messageId < this.lastMessageId) {

View file

@ -34,19 +34,27 @@
package mage.client.game; package mage.client.game;
import java.awt.Component;
import java.awt.KeyboardFocusManager;
import java.beans.PropertyVetoException;
import java.util.UUID; import java.util.UUID;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.MagePane; import mage.client.MagePane;
import mage.client.dialog.MageDialog;
import org.apache.log4j.Logger;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class GamePane extends MagePane { public class GamePane extends MagePane {
private static final Logger logger = Logger.getLogger(MageDialog.class);
/** Creates new form GamePane */ /** Creates new form GamePane */
public GamePane() { public GamePane() {
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
initComponents(); initComponents();
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
@ -65,15 +73,26 @@ public class GamePane extends MagePane {
} }
public void hideGame() { public void hideGame() {
// try { KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
MageFrame.deactivate(this);
MageFrame.getDesktop().remove(this);
gamePanel.cleanUp(); gamePanel.cleanUp();
this.getUI().uninstallUI(this); try {
this.removeAll(); this.setClosed(true);
this.dispose(); } catch (PropertyVetoException ex) {
logger.fatal("Closing Game: setClosed - ", ex);
}
MageFrame.deactivate(this);
MageFrame.getDesktop().remove(this);
logger.warn("Remove Dialog " + this.getClass().getName() + " Components left: "+ this.getComponentCount());
for (Component comp: this.getComponents()) {
logger.warn("Existing Component: " + comp.getClass().getName());
}
// this.getUI().uninstallUI(this);
// this.removeAll();
// this.dispose();
// this.setClosed(true); // this.setClosed(true);
// } catch (PropertyVetoException ex) { // } catch (PropertyVetoException ex) {
// Logger.getLogger(GamePane.class.getName()).log(Level.SEVERE, "GamePane could not be closed", ex); // Logger.getLogger(GamePane.class.getName()).log(Level.SEVERE, "GamePane could not be closed", ex);

View file

@ -249,7 +249,7 @@ public final class GamePanel extends javax.swing.JPanel {
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
logger.fatal("popupContainer error:", ex); logger.fatal("popupContainer error:", ex);
} }
this.removeAll(); // this.removeAll();
} }
private void saveDividerLocations() { private void saveDividerLocations() {

View file

@ -77,14 +77,14 @@ public class CallbackClientImpl implements CallbackClient {
@Override @Override
public synchronized void processCallback(final ClientCallback callback) { public synchronized void processCallback(final ClientCallback callback) {
logger.info(callback.getMessageId() + " - " + callback.getMethod()); logger.debug(callback.getMessageId() + " - " + callback.getMethod());
SaveObjectUtil.saveObject(callback.getData(), callback.getMethod()); SaveObjectUtil.saveObject(callback.getData(), callback.getMethod());
callback.setData(CompressUtil.decompress(callback.getData())); callback.setData(CompressUtil.decompress(callback.getData()));
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
logger.info(callback.getMessageId() + " -- " + callback.getMethod()); logger.debug(callback.getMessageId() + " -- " + callback.getMethod());
if (callback.getMethod().equals("startGame")) { if (callback.getMethod().equals("startGame")) {
TableClientMessage message = (TableClientMessage) callback.getData(); TableClientMessage message = (TableClientMessage) callback.getData();
GameManager.getInstance().setCurrentPlayerUUID(message.getPlayerId()); GameManager.getInstance().setCurrentPlayerUUID(message.getPlayerId());
@ -269,10 +269,7 @@ public class CallbackClientImpl implements CallbackClient {
Deck deck = DeckUtil.construct(deckView); Deck deck = DeckUtil.construct(deckView);
construct(deck, message.getTableId(), message.getTime()); construct(deck, message.getTableId(), message.getTime());
} else if (callback.getMethod().equals("draftOver")) { } else if (callback.getMethod().equals("draftOver")) {
DraftPanel panel = MageFrame.getDraft(callback.getObjectId()); MageFrame.removeDraft(callback.getObjectId());
if (panel != null) {
panel.hideDraft();
}
} else if (callback.getMethod().equals("draftPick")) { } else if (callback.getMethod().equals("draftPick")) {
DraftClientMessage message = (DraftClientMessage) callback.getData(); DraftClientMessage message = (DraftClientMessage) callback.getData();
DraftPanel panel = MageFrame.getDraft(callback.getObjectId()); DraftPanel panel = MageFrame.getDraft(callback.getObjectId());

View file

@ -1,6 +1,15 @@
#default levels #default levels
log4j.rootLogger=info, console, logfile log4j.rootLogger=info, console, logfile
# Suppress SQL info messages
log4j.logger.com.j256.ormlite=warn
#log4j.logger.org.jboss.remoting=debug
#log4j.logger.org.jboss.logging=debug
log4j.logger.mage.player.ai.ComputerPlayer6=debug
log4j.logger.mage.client.remote.CallbackClientImpl=debug
#log4j.logger.mage.client.remote.CallbackClientImpl=debug
log4j.logger.mage.client.game.FeedbackPanel=debug
#console log #console log
log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout=org.apache.log4j.PatternLayout

View file

@ -1,7 +1,7 @@
#default levels #default levels
log4j.rootLogger=debug, console, logfile log4j.rootLogger=debug, console, logfile
log4j.logger.com.j256.ormlite=warn log4j.logger.com.j256.ormlite=warn
#log4j.logger.mage.player.ai.ComputerPlayer6=debug
#console log #console log
log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout=org.apache.log4j.PatternLayout