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?
Increase Thread Stack Size (-Xss) Increasing the stack size can be useful, for example, when the program involves calling a large number of methods or using lots of local variables. This will set the thread's stack size to 4 mb which should prevent the JVM from throwing a java. lang. StackOverflowError .
A stack overflow is a type of buffer overflow error that occurs when a computer program tries to use more memory space in the call stack than has been allocated to that stack.
In amidst of this process, if JVM runs out of space for the new stack frames which are required to be created, it will throw a StackOverflowError. For example: Lack of proper or no termination condition. This is mostly the cause of this situation termed as unterminated or infinite recursion.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With