文档介绍:×÷Õߣºjeru
email: jeru@
ÈÕÆÚ£º7/3/2001 9:56:54 AM
3)Garbage Collection
State the behavior that is guaranteed by the garbage collection system and write code that explicitly makes objects eligible for collection.
Garbage collection is a mechanism for reclaiming memory from objects that are no longer in use, and making the memory available for new objects.
An object being no longer in use means that it can¡¯t be referenced by any ¡®active¡¯ part of the program.
Garbage collection runs in a low priority thread. It may kick in when memory is too low. No guarantee.
It¡¯s not possible to force garbage collection. Invoking may start garbage collection process.
There are no guarantees that the objects no longer in use will be garbage collected and their finalizers executed at all. gc might not even be run if the program execution does not warrant it. Thus any memory allocated during program execution might remain allocated after program termination, unless reclaimed by the OS or by other means.
There are also no guarantees on the order in which the objects will be garbage collected or on the order in which the finalizers are called.
Circular references do not prevent objects from being garbage collected.
We can set the reference variables to null, hinting the gc to garbage collect the objects referred by the variables. Even if we do that, the object may no