Q :- What is java.lang.OutOfMemoryError in Java ?
Answer :
JVM throws java.lang.OutOfMemoryError exception when required memory is not sufficient in the heap and we are try to create an object. OutOfMemoryError can come anytime in heap.
There are two types of OutOfMemoryError in Java:
Q- Is string pool garbage collected in Java ?
Q :- How to fix OutOfMemoryError Exception in Java ?
Q:- What is stack overflow exception in java ?
Q :- How to improve performance of java application ?
Q- What are the common causes of a Website Crash?
Q- What is memory leak in java ?
Ansewer :
A memory leak is a situation where some objects are no longer used by the application, but unable to Garbage Collector by JVM – due to they still have referenced. not closed in aplication.
Note :- Only the object are eligible for garbage collection which has no longer referenced.
Q :- How to detect (identify) memory leak in java application ? How to Avoid Java Memory Leaks ?
Answer :- Profiling the Heap with Java VisualVM
Following Are Symptoms Of Memory Leak
Answer :
JVM throws java.lang.OutOfMemoryError exception when required memory is not sufficient in the heap and we are try to create an object. OutOfMemoryError can come anytime in heap.
There are two types of OutOfMemoryError in Java:
- The java.lang.OutOfMemoryError: Java heap space
- The java.lang.OutOfMemoryError: PermGen space
Q- Is string pool garbage collected in Java ?
Q :- How to fix OutOfMemoryError Exception in Java ?
Q:- What is stack overflow exception in java ?
Q :- How to improve performance of java application ?
Q- What are the common causes of a Website Crash?
Q- What is memory leak in java ?
Ansewer :
A memory leak is a situation where some objects are no longer used by the application, but unable to Garbage Collector by JVM – due to they still have referenced. not closed in aplication.
Note :- Only the object are eligible for garbage collection which has no longer referenced.
Q :- How to detect (identify) memory leak in java application ? How to Avoid Java Memory Leaks ?
Following Are Symptoms Of Memory Leak
- Your application work fast while start but getting slow after some time (over time).
- Working fine with small data, but slow as data increases (large data).
- JVM throws Out-of-Memory Heap errors again and again.
- continuously crashes (no longer be accessed) your application as object increases
Common Causes Of Memory Leaks
- A memory leak can occur due to if resource, or reference of an object is not released (closed).
- Using Static reference with heavy object : like public static final ArrayList<Double> list = new ArrayList<Double>(1000000);
- Static reference are never be collected by the JVM Garbage Collector during the lifetime of the JVM process. So JVM can't reclaimed memory and the memory consumption doesn’t go down.
- Using String.intern() on Long String : The intern API will place the str String in the JVM constant pool – where it can’t be reclaimed memory (collected).
- Unclosed Streams : if we are using file i/o like BufferedReader, InputStreamReader etc. operation and forgot to close it. Solution : use try-with-resources. automatically close all types of streams
- Unclosed Connections :- most of the time we use database connection and forget to close this connection. this leading to memory problems. So make sure connection are coled after use.
- Using hashSet with no hashCode() and equals() into a HashSet.
- Using hashMap to store object of a class but hashcode() and equals() methods are not implements properly.
No comments:
Post a Comment