Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mschessler opened this issue May 29, 2022 · 5 comments
Closed

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

mschessler opened this issue May 29, 2022 · 5 comments
Labels

Comments

@mschessler
Copy link

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.

@mariuszgromada
Copy link
Owner

:-) Thanks!

@mariuszgromada
Copy link
Owner

Depending on the system configuration - OutOfMemoryError can happen everywhere ... So I will try to catch it at the very beginning, not just to handle bell number.

I will deal with tomorrow :-)

@mschessler
Copy link
Author

mschessler commented May 29, 2022

That is true. Until now I did not find other functions where a short and fast input is enough to run into a OutOfMemoryError (on a default mem. config), but it would be better to catch it on a broader scale.

@mariuszgromada
Copy link
Owner

Should work now :-)

@mariuszgromada
Copy link
Owner

mariuszgromada commented May 30, 2022

Dear @SyrasX - can you contact me on email info@mathparser.org? I want to thank you for your contribution :-)

mariuszgromada added a commit that referenced this issue May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants