Help save net neutrality! Learn more.

Need help with heap space out of memeory

  • Hao

    Hao - 2010-11-21

    I was trying to solve something like (A <= C) AND (B <= C) with all variable domain (-100, 100), but got java.lang.OutOfMemoryError: Java heap space
    when I searching for all solutions.
    Is this expected or I'm missing something?

  • kris

    kris - 2010-11-21

    The reason is that there is many solutions that are stored in the memory. In fact, you have 100*100*100 solutions. There are several ways to solve the problem. First, you can set the search in such a way that the solutions will not be stored; you only print them. For this you can use the following instructions, for example (assuming your DepthFirstSearch is called label).

          label.setSolutionListener(new PrintOutListener<IntVar>());

    The last line instructs search to not store solutions.

    If you need all solution stored, you can extend the heap size by using -Xmx option of java command.

    Good luck.

  • kris

    kris - 2010-11-21

    Sorry, you have 2,727,101 solutions ;)

  • Hao

    Hao - 2010-11-22

    I increased the heap space memory and it worked. Thanks

  • Priyanka B

    Priyanka B - 2012-07-25

    I am getting  an error saying  "java.lang.Error: java.lang.OutOfMemoryError: GC overhead limit exceeded". The no. of variables was about 32.
    I don't need to store "all" the solutions. I need just 2 of them at a time. I am using BooleanVar. I want to compare which variables in my solutions change their value across the solutions (0 to 1 or 1 to 0). So in short I have to compare the current solution to the previous solution. So I was setting recordSolutions to true and storing all the solutions. This serves my purpose but consumes a lot of memory.
    Is there any other way I can do this ? Thanks.

  • kris

    kris - 2012-07-26


    You can limit the maximum number of solutions you will get by using method setSolutionLimit() from solution listener. Below, you see a simple example of limiting number of solutions to two

    label.getSolutionListener().setSolutionLimit( 2 );

    Hope it helps,


Log in to post a comment.