Java brought garbage collection to mainstream programming. Never before have
commercial software developers been so aware of the need and benefit of using
a collector. Notwithstanding, the benefits of garbage collection in Java are
far from being completely realized. As larger and more complex applications
are built in Java, it's becoming apparent that some very flexible memory
management schemes are both needed and possible.
In this article I explore a cache you can build on JDK 1.2 beta 3 that uses
WeakReferences to cooperate with Java's garbage collector. The cache uses
WeakReferences to take advantage of available system memory without clogging
it with unfreeable objects. When memory is reclaimed, the cache will free
those objects that are not in use, resulting in a better-performing
application. Objects can be cached in memory but don't have to trigger memory
... (more)