23/04/2008
No. Java Programs may use up memory resources faster than they are garbage collected. A Java program can create objects that are not subject to garbage collection.
No. Java Programs may use up memory resources faster than they are garbage collected. A Java program can create objects that are not subject to garbage collection.



It is perfectly possible for a programmer to mistakingly create objects which never go out of scope, thus consuming more and more memory until all heap is exhausted.
It is the programmer’s responsibility to ensure that objects no longer in use are no longer referenced by the application. That way the garbage collector can do its job and reclaim memory used by these objects.
Try out the following code and check wether the GC guarentee that this application will not run out of memory
public class Main {
chandana on February 23rd, 2011 9:22 ampublic static void main(String[] main) {
List l = new LinkedList();
// Enter infinite loop which will add a String to the list: l on each iteration.
do {
l.add(new String(“Hello, World”));
} while(true);
}
}
vbngfhjg
ghjg on May 5th, 2011 1:25 pmnice example….
Achal on January 16th, 2012 12:11 pm