Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage:How fast objects are created does not affect when they are garbage collected. When the object is dereferenced it becomes available for garbage collection. If the only references to an object are from other objects that themselves are candidates for garbage collection, then that object is also a candidate for garbage collection. When memory used by the Java application reaches a certain threshold the garbage collector will automatically clean up objects that are GC candidates. "Memory leaks" in Java occur when the chain of references to objects contain "root references". Root references are references from local variables that are still part of an active call chain or static variables of loaded classes.
Category:Java Interview Questions
No comments:
Post a Comment