Memory Leaks in Java
Prajval Bhale
SDE2 @TDL | Ex - SDE @Mind Spark | Java | Spring Boot | Spring AI | Micro Services | Flutter | Angular | AWS | Kafka | Redis | Android | Google Cloud Platform | TensorFlow
After seeing the heading you might get an question like "Java will automatically takes care about memory management then how this leaks possible ?",
This is 100% right Java will take care of memory management with the help of in built garbage collector in short GC, these will takes care of allocating and freeing up memory, but.. but.. it doesn’t guarantee for foolproof solution for memory leaks. this GC is really pretty smart but not flawless.
What is Memory Leak ?
This is the situation where objects present in to heap that are no more in use but still in heap and GC is unable to clear those objects, this situation is Memory Leak.
Memory leak blocks the resources and degrades system performance over time, this will exhaust its resource finally we will face java.lang.OutOfMemoryError.
There are two objects present inside heap, Referenced and Un-Referenced, Referenced means whose reference is still active and un-referenced means who's reference is not active.
We have to know the main reason like even we have GC after that also how we will face this memory leak issues in java ?
Because, GC bhaii will clear Un-referenced objects periodically, but it never collect the objects which are still being referenced.
Now, what is symptoms of Memory Leak:
领英推荐
Types of Memory Leak and Prevent on it
Strategies for Dealing With Memory Leaks
-verbose:gc
3. Use of Referenced Objects
Conclusion:
Memory leaks are tricky to solve, and finding them requires intricate mastery and command over the Java language. While dealing with memory leaks, there’s no one-size-fits-all solution, as leaks can occur through a wide range of diverse events.