* Memory handling - some more changes to improve object deallocation.

This commit is contained in:
LevelX2 2014-02-06 18:00:45 +01:00
parent 2427b714a1
commit df9c200753
8 changed files with 51 additions and 22 deletions

View file

@ -59,6 +59,7 @@ import mage.client.util.*;
import mage.client.util.Event; import mage.client.util.Event;
import mage.view.CardView; import mage.view.CardView;
import mage.view.CardsView; import mage.view.CardsView;
import org.mage.card.arcane.CardPanel;
/** /**
* *
@ -84,14 +85,30 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
initListViewComponents(); initListViewComponents();
} }
public void clear() { public void cleanUp() {
this.clearCardEventListeners(); this.clearCardEventListeners();
if (cards != null) { if (cards != null) {
cards.clear(); cards.clear();
} }
if (mainModel != null) { if (mainModel != null) {
mainModel.removeTableModelListener(mainTable);
mainModel.clear(); mainModel.clear();
} }
if(mainTable != null) {
for(MouseListener ml: mainTable.getMouseListeners()) {
mainTable.removeMouseListener(ml);
}
}
if (currentView != null) {
currentView.clearCardEventListeners();
}
for (Component comp :cardArea.getComponents()) {
if (comp instanceof CardPanel) {
((CardPanel)comp).cleanUp();
}
}
cardArea.removeAll();
this.bigCard = null;
} }

View file

@ -164,7 +164,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
* Free all references * Free all references
* *
*/ */
public void clear() { public void cleanUp() {
this.cardGrid.clear(); this.cardGrid.clear();
this.mainModel.clear(); this.mainModel.clear();
} }

View file

@ -60,9 +60,9 @@ public class DeckArea extends javax.swing.JPanel {
sideboardList.setDisplayNoCopies(true); sideboardList.setDisplayNoCopies(true);
} }
public void clear() { public void cleanUp() {
deckList.clear(); deckList.cleanUp();
sideboardList.clear(); sideboardList.cleanUp();
} }
public void showSideboard(boolean show) { public void showSideboard(boolean show) {

View file

@ -61,6 +61,7 @@ import mage.client.constants.Constants.DeckEditorMode;
import mage.client.constants.Constants.SortBy; import mage.client.constants.Constants.SortBy;
import mage.client.dialog.AddLandDialog; import mage.client.dialog.AddLandDialog;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
import mage.client.plugins.MagePlugins;
import mage.client.plugins.adapters.MageActionCallback; import mage.client.plugins.adapters.MageActionCallback;
import mage.client.plugins.impl.Plugins; import mage.client.plugins.impl.Plugins;
import mage.client.util.Event; import mage.client.util.Event;
@ -123,7 +124,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
} }
/** /**
* Free resources so GC can work * Free resources so GC can remove unused objects from memory
*/ */
public void cleanUp() { public void cleanUp() {
if (updateDeckTask != null) { if (updateDeckTask != null) {
@ -137,9 +138,10 @@ public class DeckEditorPanel extends javax.swing.JPanel {
countdown.removeActionListener(al); countdown.removeActionListener(al);
} }
} }
this.cardSelector.clear(); this.cardSelector.cleanUp();
this.deckArea.clear(); this.deckArea.cleanUp();
this.getUI().uninstallUI(this); this.remove(bigCard);
this.bigCard = null;
((MageActionCallback) Plugins.getInstance().getActionCallback()).setCardPreviewComponent(null); ((MageActionCallback) Plugins.getInstance().getActionCallback()).setCardPreviewComponent(null);
} }

View file

@ -71,6 +71,11 @@ public final class CollectionViewerPanel extends JPanel {
} }
} }
public void cleanUp() {
this.hidePopup();
this.bigCard = null;
}
public void initComponents() { public void initComponents() {
jPanel1 = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel();
jPanel1.setOpaque(false); jPanel1.setOpaque(false);
@ -210,8 +215,7 @@ public final class CollectionViewerPanel extends JPanel {
} }
public void removeCollectionViewer() { public void removeCollectionViewer() {
hidePopup(); this.cleanUp();
Component c = this.getParent(); Component c = this.getParent();
while (c != null && !(c instanceof CollectionViewerPane)) { while (c != null && !(c instanceof CollectionViewerPane)) {
c = c.getParent(); c = c.getParent();

View file

@ -91,7 +91,7 @@ public class DraftPanel extends javax.swing.JPanel {
} }
public void cleanUp() { public void cleanUp() {
draftPicks.clear(); draftPicks.cleanUp();
draftBooster.clear(); draftBooster.clear();
if (countdown != null) { if (countdown != null) {

View file

@ -34,6 +34,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jboss.logging.Logger;
public class MageActionCallback implements ActionCallback { public class MageActionCallback implements ActionCallback {
@ -388,17 +389,20 @@ public class MageActionCallback implements ActionCallback {
final Component popupContainer = MageFrame.getUI().getComponent(MageComponents.CARD_PREVIEW_CONTAINER); final Component popupContainer = MageFrame.getUI().getComponent(MageComponents.CARD_PREVIEW_CONTAINER);
Component cardPreview = MageFrame.getUI().getComponent(MageComponents.CARD_PREVIEW_PANE); Component cardPreview = MageFrame.getUI().getComponent(MageComponents.CARD_PREVIEW_PANE);
//((CardInfoPaneImplExt) cardPreview).setCard(data.card); if (cardPreview != null) {
Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX - 40, (int) data.locationOnScreen.getY() + data.popupOffsetY - 40); Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX - 40, (int) data.locationOnScreen.getY() + data.popupOffsetY - 40);
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, cardPreview, parentComponent); location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, cardPreview, parentComponent);
location.translate(-parentPoint.x, -parentPoint.y); location.translate(-parentPoint.x, -parentPoint.y);
popupContainer.setLocation(location); popupContainer.setLocation(location);
popupContainer.setVisible(true); popupContainer.setVisible(true);
MageCard card = (MageCard) data.component; MageCard card = (MageCard) data.component;
Image image = card.getImage(); Image image = card.getImage();
BigCard bigCard = (BigCard)cardPreview; BigCard bigCard = (BigCard)cardPreview;
displayCardInfo(card, image, bigCard); displayCardInfo(card, image, bigCard);
} else {
Logger.getLogger(MageActionCallback.class).warn("No Card preview Pane in Mage Frame defined. Card: " + card.getName());
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -267,7 +267,9 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
for(MouseWheelListener ml: this.getMouseWheelListeners() ){ for(MouseWheelListener ml: this.getMouseWheelListeners() ){
this.removeMouseWheelListener(ml); this.removeMouseWheelListener(ml);
} }
// this holds reference to ActionCallback forever so set it to null to prevent
this.callback = null; this.callback = null;
this.data = null;
} }
private void setText(CardView card) { private void setText(CardView card) {