Chapter 8 |
||
Garbage Collector Interfaces and Stub/Skeleton Interfaces
The most of the modern programming languages permit you to allocate memory when a program runs. In Java, memory is allocated with the new operator. Every object that you create with the new operator uses some system resources and the storage may remain allocated longer than it is actually needed. Cleanup is a special problem because it is very easy to forget about an element. Some languages require that the programmer must explicitly release the storage. This approach is error prone, since you might release the storage too soon or forget to release it. Java has a garbage collector that automatically releases memory resources when they are no longer being used. Garbage collection can be done in a number of ways. Every garbage collection algorithm has some advantages and disadvantages. The RMI system uses a reference counting garbage collection algorithm. The RMI system keeps track of all the live references within each JVM. When a client receives a reference to a remote object, a "referenced" message is sent to the server. When a new reference is created, a reference counter is incremented. When a local reference is finalized, the reference counter is decremented. When the last reference to the object is discarded, an "unreferenced" message is sent to the server. If the remote object has no more live references, the RMI system refers to it using a weak reference. The weak reference allows the garbage collector to discard the object. The distributed garbage collector first interacts with the local garbage collector. If a remote object implements the java.rmi.Unreferenced interface, the unreferenced() method will be called when a set of references are removed. The unreferenced() method may be called more than once. The remote object will be garbage collected when no more live references exist. In case a network fails, an object may be collected prematurely.
|
||
|
||
Copyright © 2001 www.universalteacher.com |
||