Fixed memory leak

This commit is contained in:
magenoxx 2012-05-06 16:12:09 +04:00
parent 951e335997
commit 13776a0629
5 changed files with 91 additions and 63 deletions

View file

@ -97,6 +97,9 @@ public class TablesPanel extends javax.swing.JPanel {
initComponents();
// disable replays
chkShowCompleted.setVisible(false);
tableTables.createDefaultColumnsFromModel();
chatPanel.useExtendedView(ChatPanel.VIEW_MODE.NONE);
chatPanel.setBorder(null);

View file

@ -52,7 +52,6 @@ import mage.server.challenge.ChallengeManager;
import mage.server.draft.DraftManager;
import mage.server.game.*;
import mage.server.services.LogKeys;
import mage.server.services.LogService;
import mage.server.services.impl.LogServiceImpl;
import mage.server.tournament.TournamentFactory;
import mage.server.tournament.TournamentManager;
@ -432,9 +431,12 @@ public class TableController {
cancelTimeout();
startGame(choosingPlayerId);
}
// else {
// GamesRoomManager.getInstance().removeTable(table.getId());
// }
else {
GamesRoomManager.getInstance().removeTable(table.getId());
match.getGames().clear();
match = null;
table = null;
}
} catch (GameException ex) {
logger.fatal(null, ex);
}

View file

@ -72,7 +72,7 @@ public class LoadTest {
/**
* Determines how many times test will be executed in a row.
*/
private static final int EXECUTION_COUNT_PLAY_GAME = 1;
private static final int EXECUTION_COUNT_PLAY_GAME = 100;
/**
* Tests connecting with two players, creating game and starting it.
@ -128,63 +128,83 @@ public class LoadTest {
}
}
/**
* Tests 10 simple games played one after another.
*/
@Test
@Ignore
public void testSimpleGame() throws Exception {
final DeckCardLists deckList = createDeck();
for (int i = 0; i < EXECUTION_COUNT_PLAY_GAME; i++) {
final int j = i;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
testSimpleGame0(deckList, j);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
t.start();
t.join();
}
}
/**
* Tests simple game till the end (game over).
* Players do nothing but skip phases and discard cards at the end.
*
* This results in a game that lasts until there is no cards in library.
*/
@Test
@Ignore
public void testSimpleGame() throws Exception {
DeckCardLists deckList = createDeck();
private boolean testSimpleGame0(DeckCardLists deckList, int i) throws InterruptedException {
Connection connection = createConnection(TEST_USER_NAME + i);
for (int i = 0; i < EXECUTION_COUNT_PLAY_GAME; i++) {
Connection connection = createConnection(TEST_USER_NAME + i);
SimpleMageClient mageClient = new SimpleMageClient();
Session session = new SessionImpl(mageClient);
SimpleMageClient mageClient = new SimpleMageClient();
Session session = new SessionImpl(mageClient);
session.connect(connection);
session.connect(connection);
mageClient.setSession(session);
UUID roomId = session.getMainRoomId();
mageClient.setSession(session);
UUID roomId = session.getMainRoomId();
GameTypeView gameTypeView = session.getGameTypes().get(0);
log.info("Game type view: " + gameTypeView.getName());
MatchOptions options = createGameOptions(gameTypeView, session);
GameTypeView gameTypeView = session.getGameTypes().get(0);
log.info("Game type view: " + gameTypeView.getName());
MatchOptions options = createGameOptions(gameTypeView, session);
TableView table = session.createTable(roomId, options);
TableView table = session.createTable(roomId, options);
if (!session.joinTable(roomId, table.getTableId(), TEST_USER_NAME + i, "Human", 1, deckList)) {
log.error("Error while joining table");
Assert.assertTrue("Error while joining table", false);
return;
}
/*** Connect with a second player ***/
Connection connection2 = createConnection(TEST_USER_NAME_2 + i);
SimpleMageClient mageClient2 = new SimpleMageClient();
Session session2 = new SessionImpl(mageClient2);
session2.connect(connection2);
mageClient2.setSession(session2);
UUID roomId2 = session2.getMainRoomId();
// connect to the table with the same deck
if (!session2.joinTable(roomId2, table.getTableId(), TEST_USER_NAME_2 + i, "Human", 1, deckList)) {
log.error("Error while joining table");
Assert.assertTrue("Error while joining table", false);
return;
}
/*** Start game ***/
session.startGame(roomId, table.getTableId());
while (!mageClient.isGameOver()) {
Thread.sleep(1000);
}
if (!session.joinTable(roomId, table.getTableId(), TEST_USER_NAME + i, "Human", 1, deckList)) {
log.error("Error while joining table");
Assert.assertTrue("Error while joining table", false);
return true;
}
/*** Connect with a second player ***/
Connection connection2 = createConnection(TEST_USER_NAME_2 + i);
SimpleMageClient mageClient2 = new SimpleMageClient();
Session session2 = new SessionImpl(mageClient2);
session2.connect(connection2);
mageClient2.setSession(session2);
UUID roomId2 = session2.getMainRoomId();
// connect to the table with the same deck
if (!session2.joinTable(roomId2, table.getTableId(), TEST_USER_NAME_2 + i, "Human", 1, deckList)) {
log.error("Error while joining table");
Assert.assertTrue("Error while joining table", false);
return true;
}
/*** Start game ***/
session.startGame(roomId, table.getTableId());
while (!mageClient.isGameOver()) {
Thread.sleep(1000);
}
return false;
}
/**

View file

@ -386,7 +386,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
scorePlayer = state.getPlayers().values().iterator().next();
init(choosingPlayerId, options);
play(startingPlayerId);
saveState();
//saveState();
}
@Override
@ -448,7 +448,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
player.beginTurn(this);
}
fireInformEvent("game has started");
saveState();
//saveState();
//20091005 - 103.1
if (!gameOptions.skipInitShuffling) { //don't shuffle in test mode for card injection on top of player's libraries
@ -476,7 +476,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
return;
}
saveState();
//saveState();
//20091005 - 103.3
for (UUID playerId: state.getPlayerList(startingPlayerId)) {
@ -496,7 +496,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
mulligan(player.getId());
}
fireInformEvent(player.getName() + " keeps hand");
saveState();
//saveState();
}
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
@ -627,8 +627,8 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
Player player;
while (!isPaused() && !isGameOver()) {
try {
if (bookmark == 0)
bookmark = bookmarkState();
//if (bookmark == 0)
//bookmark = bookmarkState();
player = getPlayer(state.getPlayerList().get());
state.setPriorityPlayerId(player.getId());
while (!player.isPassed() && !player.hasLost() && !player.hasLeft() && !isPaused() && !isGameOver()) {
@ -654,7 +654,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
state.getRevealed().reset();
break;
} else {
removeBookmark(bookmark);
//removeBookmark(bookmark);
return;
}
}
@ -662,13 +662,13 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
catch (Exception ex) {
logger.fatal("Game exception ", ex);
this.fireErrorEvent("Game exception occurred: ", ex);
restoreState(bookmark);
//restoreState(bookmark);
bookmark = 0;
continue;
}
state.getPlayerList().getNext();
}
removeBookmark(bookmark);
//removeBookmark(bookmark);
bookmark = 0;
}
} catch (Exception ex) {

View file

@ -28,15 +28,16 @@
package mage.game.turn;
import mage.Constants.PhaseStep;
import mage.Constants.TurnPhase;
import mage.game.Game;
import mage.players.Player;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import mage.Constants.PhaseStep;
import mage.Constants.TurnPhase;
import mage.game.Game;
import mage.players.Player;
/**
*
@ -121,7 +122,9 @@ public class Turn implements Serializable {
if (phase.play(game, activePlayerId)) {
//20091005 - 500.4/703.4n
game.emptyManaPools();
game.saveState();
//game.saveState();
//20091005 - 500.8
playExtraPhases(game, phase.getType());
}