mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
Performance: fixed memory leaks on each card viewer or draft open (10 Mb per call, related to #11285, fixes #9548)
This commit is contained in:
parent
ce311fd691
commit
36ccfb0a2a
13 changed files with 44 additions and 10 deletions
|
|
@ -24,6 +24,10 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Network: client side session
|
||||||
|
*
|
||||||
|
* Only one session/server per GUI's client
|
||||||
|
*
|
||||||
* Created by IGOUDT on 15-9-2016.
|
* Created by IGOUDT on 15-9-2016.
|
||||||
*/
|
*/
|
||||||
public final class SessionHandler {
|
public final class SessionHandler {
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
|
||||||
MageFrame.getPreferences().put(KEY_DECK_EDITOR_SEARCH_RULES, Boolean.toString(chkRules.isSelected()));
|
MageFrame.getPreferences().put(KEY_DECK_EDITOR_SEARCH_RULES, Boolean.toString(chkRules.isSelected()));
|
||||||
MageFrame.getPreferences().put(KEY_DECK_EDITOR_SEARCH_TYPES, Boolean.toString(chkTypes.isSelected()));
|
MageFrame.getPreferences().put(KEY_DECK_EDITOR_SEARCH_TYPES, Boolean.toString(chkTypes.isSelected()));
|
||||||
MageFrame.getPreferences().put(KEY_DECK_EDITOR_SEARCH_UNIQUE, Boolean.toString(chkUnique.isSelected()));
|
MageFrame.getPreferences().put(KEY_DECK_EDITOR_SEARCH_UNIQUE, Boolean.toString(chkUnique.isSelected()));
|
||||||
|
ExpansionRepository.instance.unsubscribe(setsDbListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeGUISize() {
|
public void changeGUISize() {
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ public final class CollectionViewerPanel extends JPanel {
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
this.hidePopup();
|
this.hidePopup();
|
||||||
this.bigCard = null;
|
this.bigCard = null;
|
||||||
|
ExpansionRepository.instance.unsubscribe(setsDbListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reloadFormatCombobox() {
|
private void reloadFormatCombobox() {
|
||||||
|
|
@ -220,7 +221,6 @@ public final class CollectionViewerPanel extends JPanel {
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
((CollectionViewerPane) c).removeFrame();
|
((CollectionViewerPane) c).removeFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class MageBookContainer extends JPanel {
|
private final class MageBookContainer extends JPanel {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package mage.client.util;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* TODO: there are duplicated interfaces of EventSource, must combine in single
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public interface EventSource<E extends Event> extends Serializable {
|
public interface EventSource<E extends Event> extends Serializable {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import mage.constants.SetType;
|
||||||
import mage.deck.Standard;
|
import mage.deck.Standard;
|
||||||
import mage.game.events.Listener;
|
import mage.game.events.Listener;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -54,6 +55,7 @@ public final class ConstructedFormats {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// it's a static, so no needs to unsubscribe later
|
||||||
ExpansionRepository.instance.subscribe(setsDbListener);
|
ExpansionRepository.instance.subscribe(setsDbListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Network: client side session
|
||||||
|
*
|
||||||
* @author BetaSteward_at_googlemail.com, JayDi85
|
* @author BetaSteward_at_googlemail.com, JayDi85
|
||||||
*/
|
*/
|
||||||
public class SessionImpl implements Session {
|
public class SessionImpl implements Session {
|
||||||
|
|
|
||||||
|
|
@ -607,7 +607,7 @@ public class TableController {
|
||||||
logger.info("Tourn. match started id:" + match.getId() + " tournId: " + table.getTournament().getId());
|
logger.info("Tourn. match started id:" + match.getId() + " tournId: " + table.getTournament().getId());
|
||||||
} else {
|
} else {
|
||||||
managerFactory.userManager().getUser(userId).ifPresent(user -> {
|
managerFactory.userManager().getUser(userId).ifPresent(user -> {
|
||||||
logger.info("MATCH started [" + match.getName() + "] " + match.getId() + '(' + user.getName() + ')');
|
logger.info("MATCH started [" + match.getName() + "] " + match.getId() + " (" + user.getName() + ')');
|
||||||
logger.debug("- " + match.getOptions().getGameType() + " - " + match.getOptions().getDeckType());
|
logger.debug("- " + match.getOptions().getGameType() + " - " + match.getOptions().getDeckType());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -566,7 +566,7 @@ public class User {
|
||||||
if (!watchedGames.isEmpty()) {
|
if (!watchedGames.isEmpty()) {
|
||||||
sb.append("Watch: ").append(watchedGames.size()).append(' ');
|
sb.append("Watch: ").append(watchedGames.size()).append(' ');
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.length() == 0 ? "not active" : sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addGameWatchInfo(UUID gameId) {
|
public void addGameWatchInfo(UUID gameId) {
|
||||||
|
|
|
||||||
|
|
@ -62,10 +62,19 @@ public enum ExpansionRepository {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warning, don't forget to unsubscribe due memory leak problems
|
||||||
|
*
|
||||||
|
* @param listener
|
||||||
|
*/
|
||||||
public void subscribe(Listener<RepositoryEvent> listener) {
|
public void subscribe(Listener<RepositoryEvent> listener) {
|
||||||
eventSource.addListener(listener);
|
eventSource.addListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unsubscribe(Listener<RepositoryEvent> listener) {
|
||||||
|
eventSource.removeListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
public void saveSets(final List<ExpansionInfo> newSets, final List<ExpansionInfo> updatedSets, long newContentVersion) {
|
public void saveSets(final List<ExpansionInfo> newSets, final List<ExpansionInfo> updatedSets, long newContentVersion) {
|
||||||
try {
|
try {
|
||||||
expansionDao.callBatchTasks(() -> {
|
expansionDao.callBatchTasks(() -> {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,12 @@ public class RepositoryEventSource implements EventSource<RepositoryEvent>, Seri
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAllListener() {
|
public void removeListener(Listener<RepositoryEvent> listener) {
|
||||||
|
dispatcher.removeListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeAllListeners() {
|
||||||
dispatcher.removeAllListener();
|
dispatcher.removeAllListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
|
|
||||||
|
|
||||||
package mage.game.events;
|
package mage.game.events;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* TODO: there are duplicated interfaces of EventSource, must combine in single
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
* @param <E>
|
* @param <E>
|
||||||
*/
|
*/
|
||||||
public interface EventSource<E extends ExternalEvent> extends Serializable {
|
public interface EventSource<E extends ExternalEvent> extends Serializable {
|
||||||
|
|
||||||
void addListener(Listener<E> listener);
|
void addListener(Listener<E> listener);
|
||||||
|
|
||||||
|
void removeListener(Listener<E> listener);
|
||||||
|
|
||||||
void removeAllListener();
|
void removeAllListeners();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,12 @@ public class PlayerQueryEventSource implements EventSource<PlayerQueryEvent>, Se
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAllListener() {
|
public void removeListener(Listener<PlayerQueryEvent> listener) {
|
||||||
|
dispatcher.removeListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeAllListeners() {
|
||||||
dispatcher.removeAllListener();
|
dispatcher.removeAllListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,12 @@ public class TableEventSource implements EventSource<TableEvent>, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAllListener() {
|
public void removeListener(Listener<TableEvent> listener) {
|
||||||
|
dispatcher.removeListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeAllListeners() {
|
||||||
dispatcher.removeAllListener();
|
dispatcher.removeAllListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue