java OOM handling and SOF

A, OOM

  Memory overflow, refers to the program at the time of application memory, there is not enough space for its use, there was Out Of Memory, which is required to allocate memory beyond the system can give you, the system can not meet the demand, so the overflow.

  Memory leaks can cause memory overflow, so-called memory leaks (memory leak), refers to the program after the application memory to free up memory space has been filed, a memory leak hazards can be ignored, but the memory leak accumulation of very serious consequences, no matter how much memory, sooner or later occupied light

(1) OOM encounter

  1, Java Heap Overflow: Java heap is used to store an object instance, as long as continue to create an object, but no timely recovery of these objects (ie memory leaks), will reach the maximum heap size limit on the number of objects generated after memory overflow exception.

  2. The method overflow: overflow is also a common method of memory overflow exception, if a class is to be garbage collected, determination condition is very harsh. In applications often dynamically generated in a large number of Class, paying particular attention to this point.

(2) solve OOM

  1, in the memory references do Remedy: Before jvm report insufficient memory will clear all soft references, such gc since it is possible to collect softly reachable objects may solve the problem of tight memory and avoid memory overflow. When it will be collected depending on available memory gc gc algorithms and runtime size.

  2, the display memory is recovered GC calls, such as: if (bitmapObject.isRecycled () == false) // If no recovery bitmapObject.recycle ();

  3, the heap memory size: -Xms and -Xmx (-XX: InitialHeapSize and -XX: MaxHeapSize): JVM specified initial buffer occupancy and the maximum heap memory heap memory.

Two, SOF

  Recursion too deep when the application stack overflow occurs, the error is thrown. Because the default stack is generally 1-2m, once an infinite loop or a large number of recursive calls, constantly push the process, resulting in a stack overflow capacity of more than 1m caused. (1) stack overflow reasons:

  1, recursive call.

  2, a large number of cycles and the cycle of death.

(2) to solve the problem: Check your own code.

    

Guess you like

Origin www.cnblogs.com/hdc520/p/12599521.html