

Presently, with the rich set of JDK library classes and an even richer choice of third-party open-source code, with powerful IDEs and, above all, the powerful yet "forgiving" language that Java has become, the situation is different. In the old, pre-Java days, writing a big program in C++ was a slow, sometimes painful, process that required a serious effort of a well-coordinated group of developers. One can argue that they are a side effect of the power of the language and its ecosystem. So, why is "memory leak" still one of the common problems with memory in Java apps? If you are wondering about it or have ever struggled to try to understand why your app's used memory keeps growing, read on.īriefly speaking, memory leaks in Java are not real leaks - they are simply data structures that grow uncontrolled due to errors or suboptimal code. become inaccessible to the running program yet use up memory - not for long time, anyway.

So, no object in Java can really "leak," i.e. The most common GC roots are local variables in methods and static data fields an object is reachable when a GC root points to it directly or through a chain of other objects.

At runtime, any object that is not reachable from a GC root will be automatically destroyed and its memory recycled (sooner or later). One of the main reasons for Java's popularity is Garbage Collection.
