top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

IS memory leak possible in JAVA. If yes, then how?

+3 votes
342 views
IS memory leak possible in JAVA. If yes, then how?
posted Dec 26, 2014 by Prakash

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Though it largely depends on the definition of the memory leak -

In C or C++ if a programmer misses a free or delete statement then it results in memory leak. But in Java one in most of the cases does not suffer from this as garbage collector takes care of freeing objects that are no longer reachable.

As I said mostly, in some cases GC can miss objects that (from the perspective of the programmer) should be garbage collected. This happens when the GC cannot figure out that an object cannot be reached:

The logic / state of the program might be such that the execution paths that would use some variable cannot occur. The developer can see this as obvious, but the GC cannot be sure and results in leak.

answer Dec 28, 2014 by Salil Agrawal
...