* 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.view.CardView;
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();
}
public void clear() {
public void cleanUp() {
this.clearCardEventListeners();
if (cards != null) {
cards.clear();
}
if (mainModel != null) {
mainModel.removeTableModelListener(mainTable);
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
*
*/
public void clear() {
public void cleanUp() {
this.cardGrid.clear();
this.mainModel.clear();
}

View file

@ -60,9 +60,9 @@ public class DeckArea extends javax.swing.JPanel {
sideboardList.setDisplayNoCopies(true);
}
public void clear() {
deckList.clear();
sideboardList.clear();
public void cleanUp() {
deckList.cleanUp();
sideboardList.cleanUp();
}
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.dialog.AddLandDialog;
import mage.client.dialog.PreferencesDialog;
import mage.client.plugins.MagePlugins;
import mage.client.plugins.adapters.MageActionCallback;
import mage.client.plugins.impl.Plugins;
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() {
if (updateDeckTask != null) {
@ -137,9 +138,10 @@ public class DeckEditorPanel extends javax.swing.JPanel {
countdown.removeActionListener(al);
}
}
this.cardSelector.clear();
this.deckArea.clear();
this.getUI().uninstallUI(this);
this.cardSelector.cleanUp();
this.deckArea.cleanUp();
this.remove(bigCard);
this.bigCard = 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() {
jPanel1 = new javax.swing.JPanel();
jPanel1.setOpaque(false);
@ -210,8 +215,7 @@ public final class CollectionViewerPanel extends JPanel {
}
public void removeCollectionViewer() {
hidePopup();
this.cleanUp();
Component c = this.getParent();
while (c != null && !(c instanceof CollectionViewerPane)) {
c = c.getParent();

View file

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

View file

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

View file

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