Skip to content

BellNumber java.lang.OutOfMemoryError: Java heap space #262

@mschessler

Description

@mschessler

MathParser.org-mXparser version: v.5.0.5
Framework: java

A big value n for the BellNumber Bell(n) leads to an OutOfMemoryError.

public class Tester {

    public static void callApi(String input){
  
      Expression e = new Expression(input);
      e.setVerboseMode();
      if(e.checkSyntax()){
        e.calculate();
      }
    }
  
    public static void main(String[] args){

        callApi("Bell(999999*9999999)");
    }
}

Log:

[mXparser-v.5.0.5]
[][Bell(9999999999999)]
[][Bell(999999
9999999)] Starting ...
[][Bell(9999999999999)] Starting calculation loop
[][Bell(999999
9999999)] Parsing (1, 5) ---> ( 999999.0 * 9999999.0 ) ... ---> Bell ( 9.999989000001E12 ) ... done
[][Bell(9999999999999)] Parsing (1, 3) ---> ( 9.999989000001E12 ) ... ---> Bell 9.999989000001E12 ... done
[][Bell(999999
9999999)] Parsing (0, 1) ---> Bell 9.999989000001E12 ... Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.mariuszgromada.math.mxparser.mathcollection.MathFunctions.bellNumber(MathFunctions.java:300)
at org.mariuszgromada.math.mxparser.mathcollection.MathFunctions.bellNumber(MathFunctions.java:328)
at org.mariuszgromada.math.mxparser.Expression.BELL_NUMBER(Expression.java:3558)
at org.mariuszgromada.math.mxparser.Expression.f1ArgCalc(Expression.java:6373)
at org.mariuszgromada.math.mxparser.Expression.calculate(Expression.java:6179)
at org.mariuszgromada.math.mxparser.Expression.calculate(Expression.java:5666)
at Tester.callApi(Tester.java:11)
at Tester.main(Tester.java:17)

I tried other java algorithms found on the web but they also had the same result. So probably should just catch the Exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions