File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes What is Memory Leakage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "What is Memory Leakage" Watch "What is Memory Leakage" New topic

What is Memory Leakage

amit bhadre
Ranch Hand

Joined: Jan 23, 2006
Posts: 124
What is Memory leakage in java and how it handles?

Thanks advance who ever answers this question.

amit bhadre
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3640
Memeory Leakage and Memory Managment in Java.
[ March 11, 2006: Message edited by: Chetan Parekh ]

My blood is tested +ve for Java.
amit bhadre
Ranch Hand

Joined: Jan 23, 2006
Posts: 124

amit bhadre
ak pillai
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
In Java, typically memory leak occurs when an object of a longer lifecycle has a reference to objects of a short life cycle. This prevents the objects with short life cycle being garbage collected. The developer must remember to remove the references to the short-lived objects from the long-lived objects. Objects with the same life cycle do not cause any issues because the garbage collector is smart enough to deal with the circular references.

--Design applications with an object�s life cycle in mind, instead of relying on the clever features of the JVM. Letting go of the object�s reference in one�s own class as soon as possible can mitigate memory problems. Example: myRef = null;

--Unreachable collection objects can magnify a memory leak problem. In Java it is easy to let go of an entire collection by setting the root of the collection to null. The garbage collector will reclaim all the objects (unless some objects are needed elsewhere).

--Also, take care, while writing singletons, because they are long lived objects.

java j2ee job interview questions with answers | Learn the core concepts and the key areas
I agree. Here's the link:
subject: What is Memory Leakage
It's not a secret anymore!