问题
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?
回答1:
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
回答2:
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;
}
来源:https://stackoverflow.com/questions/37316833/getting-error-java-lang-stackoverflowerror-stack-size-1036kb-and-outofmemory