garbage collection

A Java WeakHashMap class example

I ran across some Java source code today that I thought I should share. This code demonstrates how to use the Java WeakHashMap class, which can serve as a nice cache some times. I particularly like how this class responds to available memory and the Java garbage collection system.

Let me share the Java source code here first, and then I'll provide a description of how it works:

Java Runtime class - Invoke the Java garbage collector

Note: This article is very old, like 1990s-old. In the 90s we did things like this, but manually manipulating theJava garbage collector in the 201x years is not a best-practice. That being said, I'm leaving this article here for historical reasons.

Summary: This article demonstrates how to use the Java Runtime class to invoke the Java garbage collector, and shows the results of running the Java Runtime freeMemory method in an example class.