Когда я запускаю свою программу с 8 головоломками, я продолжаю получать «превышение верхнего предела GC». Я попытался добавить больше памяти в JVM, но это не помогло.8-головоломка java.lang.OutOfMemoryError: превышен верхний предел GC
Вот метод, который является проблемой:
public void search() {
addToQueue(start, null);// add root
while (!queue.isEmpty()) {
currState = queue.removeFirst();
if (goal.equals(currState)) {
solution = true;
printSolution(currState);
break;
} else {
a = currState.indexOf("0");
// left
while (a != 0 && a != 3 && a != 6) {
String nextState = currState.substring(0, a - 1) + "0"
+ currState.charAt(a - 1)
+ currState.substring(a + 1);
addToQueue(nextState, currState);
nodes++;
break;
}
// up
while (a != 0 && a != 1 && a != 2) {
String nextState = currState.substring(0, a - 3) + "0"
+ currState.substring(a - 2, a)
+ currState.charAt(a - 3)
+ currState.substring(a + 1);
addToQueue(nextState, currState);
nodes++;
break;
}
// right
while (a != 2 && a != 5 && a != 8) {
String nextState = currState.substring(0, a)
+ currState.charAt(a + 1) + "0"
+ currState.substring(a + 2)
+ currState.substring(a + 1);
addToQueue(nextState, currState);
nodes++;
break;
}
// down
while (a != 6 && a != 7 && a != 8) {
String nextState = currState.substring(0, a)
+ currState.substring(a + 3, a + 4)
+ currState.substring(a + 1, a + 3) + "0"
+ currState.substring(a + 4);
addToQueue(nextState, currState);
nodes++;
break;
}
}
}
}
Start является строка, что я прочитал в из файла .txt. Он будет работать для некоторых проблем, но некоторые вызовут эту ошибку.
private void addToQueue(String newState, String oldState) {
if (!levelDepth.containsKey(newState)) {
newValue = oldState == null ? 0 : levelDepth.get(oldState) + 1;
unique++;
levelDepth.put(newState, newValue);
queue.add(newState);
stateHistory.put(newState, oldState);
}
}
Есть ли еще сообщения об ошибке? Означает ли это имя строки или метода линии или указывает какие-либо объекты? – iamnotmaynard
Является ли обработка приложений чрезмерно продолжительным? Вы просматриваете большой набор данных? – Taylor
@ Тейлор работает в течение длительного периода времени. – pacman4565