I have an Alloy model that, when running in Alloy tool (alloy4.2.jar), generates instances without any problems. But, when I use this same model as input to the Alloy api in Java in order to get all of these instances, one by one, an out of memory error is generated after a while (many instances are captured before the error appears).
The error occurs exactly in the if command located just after the try command (corresponding to JDolly.java:192 in the print stack trace further) in the code below:
@Override
public boolean hasNext() {
// primeira vez
if (firstTime) initializeAlloyAnalyzer();
if (currentAns.satisfiable() && firstTime) {
firstTime = false;
return true;
}
if (maximumPrograms > 0 && maximumPrograms == currentProgram) return false;
boolean result = true;
try {
if (!currentAns.next().satisfiable() || currentAns.equals(currentAns.next())){
result = false;
System.out.println("TARCIANA -- non satisfiable, linha 194");
} else {
currentAns = currentAns.next();
}
} catch (Err e) {
result = false;
e.printStackTrace();
}
return result;
}
The print stack trace of this error is:
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at kodkod.util.collections.IdentityHashSet.<init>(IdentityHashSet.java:162)
at kodkod.util.nodes.AnnotatedNode$SharingDetector.sharedNodes(AnnotatedNode.java:278)
at kodkod.util.nodes.AnnotatedNode.<init>(AnnotatedNode.java:92)
at kodkod.util.nodes.AnnotatedNode.annotate(AnnotatedNode.java:114)
at kodkod.engine.fol2sat.Translator.evaluate(Translator.java:104)
at kodkod.engine.Evaluator.evaluate(Evaluator.java:117)
at edu.mit.csail.sdg.alloy4compiler.translator.A4Solution.rename(A4Solution.java:844)
at edu.mit.csail.sdg.alloy4compiler.translator.A4Solution.rename(A4Solution.java:841)
at edu.mit.csail.sdg.alloy4compiler.translator.A4Solution.rename(A4Solution.java:824)
at edu.mit.csail.sdg.alloy4compiler.translator.A4Solution.<init>(A4Solution.java:330)
at edu.mit.csail.sdg.alloy4compiler.translator.A4Solution.next(A4Solution.java:1031)
at ejdolly.JDolly.hasNext(JDolly.java:192)
at org.testorrery.ForLoopIterator.hasNext(ForLoopIterator.java:40)
at refactoringTest.RefactoringTest.runTests(RefactoringTest.java:141)
at refactoringTest.MainRunner.main(MainRunner.java:83)
I think the reason of this error can be the same as the one described in: CapacityExceededException when reading a very large instance using A4SolutionReader
Any suggestions in order to avoid this error?