GUI: fixed memory leak on gui-desktop

This commit is contained in:
Hans Mackowiak
2020-12-03 10:44:20 +01:00
parent 772b0c4eae
commit ecb010ed41
5 changed files with 37 additions and 29 deletions

View File

@@ -223,7 +223,6 @@ public class Game {
rules = rules0;
match = match0;
this.id = nextId();
match.addGame(this);
int highestTeam = -1;
for (RegisteredPlayer psc : players0) {

View File

@@ -24,11 +24,13 @@ import java.util.List;
public class GameView extends TrackableObject {
private static final long serialVersionUID = 8522884512960961528L;
private final transient Game game; //TODO: Remove this when possible before network support added
private final transient Match match; //TODO: Remove this when possible before network support added
public GameView(final Game game) {
super(game.getId(), game.getTracker());
match = game.getMatch();
this.game = game;
set(TrackableProperty.Title, game.getMatch().getTitle());
set(TrackableProperty.WinningTeam, -1);
@@ -48,7 +50,7 @@ public class GameView extends TrackableObject {
}
public Game getGame() {
return getMatch().getGameById(getId()); // Match currently has only One running Game
return game;
}
public FCollectionView<PlayerView> getPlayers() {

View File

@@ -33,7 +33,6 @@ public class Match {
private final String title;
private final EventBus events = new EventBus("match events");
private final Map<Integer, Game> runningGames = Maps.newHashMap();
private final Map<Integer, GameOutcome> gameOutcomes = Maps.newHashMap();
private GameOutcome lastOutcome = null;
@@ -97,25 +96,15 @@ public class Match {
// will pull UI dialog, when the UI is listening
game.fireEvent(new GameEventGameFinished());
// FIXME needed to close the Match Dialog because that this moment there isn't any game
runningGames.remove(game.getId());
//run GC after game is finished
System.gc();
}
public Game getGameById(int id) {
return runningGames.get(id);
}
public GameOutcome getOutcomeById(int id) {
return gameOutcomes.get(id);
}
public void addGame(Game game) {
runningGames.put(game.getId(), game);
}
public void clearGamesPlayed() {
gameOutcomes.clear();
for (RegisteredPlayer p : players) {

View File

@@ -134,6 +134,7 @@ import forge.util.gui.SOptionPane;
import forge.view.FView;
import forge.view.arcane.CardPanel;
import forge.view.arcane.FloatingZone;
import net.miginfocom.layout.LinkHandler;
import net.miginfocom.swing.MigLayout;
/**
@@ -1028,6 +1029,7 @@ public final class CMatchUI
FThreads.invokeInEdtNowOrLater(new Runnable() {
@Override public void run() {
Singletons.getView().getNavigationBar().closeTab(screen);
LinkHandler.clearWeakReferencesNow();
}
});
}

View File

@@ -2214,7 +2214,7 @@ public class FSkin {
}
private static class SkinScrollBarUI extends BasicScrollBarUI implements ILocalRepaint {
@SuppressWarnings("serial")
private static JButton hiddenButton = new JButton() {
private static class HiddenButton extends JButton {
@Override
public Dimension getPreferredSize() {
return new Dimension(0, 0);
@@ -2229,26 +2229,42 @@ public class FSkin {
private final boolean vertical;
private boolean hovered;
private MouseAdapter hoverListener;
private static class SkinScrollBarListener extends MouseAdapter {
private SkinScrollBarUI barUI;
private SkinScrollBarListener(SkinScrollBarUI barUI) {
this.barUI = barUI;
}
@Override
public void mouseEntered(final MouseEvent e) {
barUI.hovered = true;
barUI.repaintSelf();
}
@Override
public void mouseExited(final MouseEvent e) {
barUI.hovered = false;
barUI.repaintSelf();
}
}
private SkinScrollBarUI(final JScrollBar scrollbar, final boolean vertical0) {
vertical = vertical0;
scrollbar.setOpaque(false);
scrollbar.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(final MouseEvent e) {
hovered = true;
repaintSelf();
}
@Override
public void mouseExited(final MouseEvent e) {
hovered = false;
repaintSelf();
}
});
hoverListener = new SkinScrollBarListener(this);
scrollbar.setOpaque(false);
scrollbar.addMouseListener(hoverListener);
scrollbar.setUI(this);
}
protected void uninstallListeners() {
super.uninstallListeners();
scrollbar.removeMouseListener(hoverListener);
}
@Override
public void repaintSelf() {
final Dimension d = scrollbar.getSize();
@@ -2257,12 +2273,12 @@ public class FSkin {
@Override
protected JButton createIncreaseButton(final int orientation) {
return hiddenButton; //hide increase button
return new HiddenButton(); //hide increase button
}
@Override
protected JButton createDecreaseButton(final int orientation) {
return hiddenButton; //hide decrease button
return new HiddenButton(); //hide decrease button
}
@Override