ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What cause ( stack overflow error , out of memory error ) and how to solve it ?

user-image
تم إضافة السؤال من قبل Adel Ezat Fawzy Ellozy , Webdeveloper. , Saudi Arabian Maritiem Sports Federation
تاريخ النشر: 2017/04/07
Shadi Al Barhouch
من قبل Shadi Al Barhouch , Developer , THALES GROUP

OitOfmemoreyError is thrown when the jvm is not able to free the heapdum of the JVM . There are three solutions

1- Increse the heapdump using -Xms=512M for example

2-Use -XX:PermSize since the jvm free 32M each shot and this increase it

--XX:PermSize=128M

3- Use JProfiler or MemoreyLeakDetector rool to see where are the instances that occupy the memorey

StackOverflow is thrown when there are infinit recursive call

Most developer make mistake by modifying broken condition after processing

Example:

//This may cause StackOverflow

Object obj = checkObject();

if(set.contans(obj)){

return;

}

callRecursive(obj,set);

set.add(obj);

//solution

Object obj = checkObject();

if(set.contans(obj)){

return;

}

set.add(obj);

callRecursive(obj,set);

 

 

Julien-Yusef Neidballa
من قبل Julien-Yusef Neidballa , Trading Platform Software Engineer , Fidessa Group plc

Stack overflow is usually caused by unbounded recursion, whereas the Out of Memory error is the result of trying to use more space for program memory than is available in the heap (you may want to look at the -Xmxn command line switch)

StackOverflowError : the stack as OutOfMemoryError : the heap

Mohd Faisal
من قبل Mohd Faisal , Senior Mobile Application Developer(Android/iOS/Flutter) , Naqel Express

 

 

1# StackOverFlow Error

 

When a function call is invoked by a Java application, a stack frame is allocated on the call stack. The stack frame contains the parameters of the invoked method, its local parameters, and the return address of the method. If there is no space for a new stack frame then, the stackoverflow is thrown by the Java Virtual Machine (JVM).

 

For an example:

intcheckOverFlow(){inta=;System.out.println(a)checkOverFlow()}

 

checkOverFlow()calling itself again again,and when the space used to keep track of what functions you're in is filled up, you get the stack overflow error.Solution:-

1.Ifyour are calling any methodagain & again .Try to check if there is a stopping condition to ur recursive call.

2.avoid deep recursion.

3.Avoid large stack variables

 

2#OutOfMemoryError

Javamemory is separated into two different regions. These regions arecalled Heap space and Permgen.Theremost common reason for the  Outof Memory (heap error)erroris simple – you try to fit an XXL application into an S-sized Javaheap space. That is the application just requires more Java heapspace than available to it to operate normally. Other causes for thisOutOfMemoryError message are more complex and are caused by aprogramming error.

Solution:-

1.Data Volume:-The application was designed to handle a certain amount of users or a certain amount of data. When the number of users or the volume of data suddenly spikes and crosses that expected threshold, the operation which functioned normally before the spike ceases to operate and triggers the Out of Memory (heap error)error.

2.memory leaks:- A particular type of programming error will lead your application to constantly consume more memory. Every time the leaking functionality of the application is used it leaves some objects behind into the Java heap space. Over time the leaked objects consume all of the available Java heap space and trigger the already familiar  Out of Memory (heap error)error.

Amir ahmed Ibrahim
من قبل Amir ahmed Ibrahim , Engineering Manager , talabat

Many reasons could cause out of memory exception, loading large amount of data and processing it in a very long iteration could cause the error, you may have a very long iteration to process or import some data without any GC.To solve this error, mainly good application or bulk code design, then you may enforce GC.

المزيد من الأسئلة المماثلة