next up previous contents
Next: The HsCache Service Up: The HsPersistentObjectService Previous: The HsPersistentObjectService

Future Improvements

One of the fundamental problems of the HsPersistentObjectService is its inability to clean its cache. This leads to the constant growth of the memory requirements of any running Haystack session. As it is impossible to count the number of services holding a pointer to any particular Straw we can never be certain if it is safe to remove the Straw from the cache. If we removed the Straw and someone modifies it at some later point, the change will not be saved. The simple solution is to rely on the Java garbage collection mechanism which will eventually remove a Straw that nobody is holding from memory. Unfortunately, as long as the cache holds the Straw, it will never be garbage collected.

Fortunately, Java 1.2 provides a new type of object reference (pointer). These references are known as ``weak references.'' Weak reference objects maintain a pointer to an object. If nothing else has a strong reference (i.e. is holding a pointer) to the object, the garbage collector can remove the object from memory. If the HsPersistentObjectService cache maintained only weak references to the Straws the garbage collector could still remove the object from memory and allow the Haystack memory footprint to remain manageable.



Copyright 1998, Eytan Adar (eytan@alum.mit.edu)