Management of heap memory is well supported in Java, thanks to its
garbage collector. Memory, however, is not the only resource that needs
to be managed in a Java program. In this tutorial we explore how Java supports
management of resources other than heap memory.
The most common problem with resource management is improper release
of acquired resources. The Java language offers a number of language constructs
for cleanup activities such as resource release, namely finalizers, the
finally clause, and reference objects.
Close examination of these mechanisms reveals that the amount of control
provide over resource release is limited and might be dissatisfactory if
reliable resource release is of paramount importance. We will see that
there is no guarantee that a finalizer will ever be invoked; we will talk
about unwanted references and why they are a problem, and we will explore
whether and how soft, weak, and phantom references mitigate the problems. |