13

I am working with an application having totally work with Images and Videos. I am storing all the images and videos of device into database of application and this task is performing in a background service. Between this process I am checking for detecting face in image using getFacesFromBitmap(mBitmap).

The problem is that sometime I am getting error java.lang.StackOverflowError: stack size 1036KB and sometimes I am getting OOM error.

So is there any best way to solve this issue?

3 Answers 3

14

StackOverflowError is usually caused by an overwhelming stack size (too many methods calling each other)

Sometimes it is caused by methods calling themselves recursively (imagine a method that keeps calling itself forever!).

Fixing the issue depends on whether it is caused by a programmatic mistake, or just an insufficient max-stack-size limitation on your application.

I recommend that you check your code for recursive calls and make sure no method will keep calling itself endlessly.

The other option (after you make sure there are no problems with your code) is to increase the stack size of your program, e.g.: Tomcat has a parameter named "-Xss" that can be used to tune the maximum stack size, check the link below:

http://www.tomcatexpert.com/blog/2011/11/22/performance-tuning-jvm-running-tomcat

Sign up to request clarification or add additional context in comments.

2 Comments

This makes sense (imagine a method that keeps calling itself forever!), Thanks.
This was exactly my issue. There was an accidental recursive function calling over and over again.
4

Yes,

It's going to happen because of calling the function recursively.

Before calling the function... Just sleep for 2000/3000 seconds

    private String getRegKey() {

    String regId = pref.getString("regId", null);

    if (!TextUtils.isEmpty(regId)) {

        //registration id recieved
        Log.e("reg key","is"+regId);
    } else {

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        getRegKey();
    }

    return regId;
}

Comments

0

I faced this issue when i tried to show bulk of data into logs using Gson forexample So if you have data in bulk then try to call this into separate thread.

Log.d("TAG", "tgX6Values: "+new Gson().toJson(tgX6Values));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.