Angelika Langer - Training & Consulting
HOME | COURSES | TALKS | ARTICLES | GENERICS | LAMBDAS | IOSTREAMS | ABOUT | CONTACT | Twitter | Lanyrd | Linkedin
HOME 


  UPCOMING
  PREVIOUS
  MATERIALS
 
GENERICS 
LAMBDAS 
IOSTREAMS 
ABOUT 
CONTACT 
Resource Management in Java - Finalization and Unwanted References

Resource Management in Java - Finalization and Unwanted References
ABSTRACT
 
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. 

 
 
OUTLINE
 
    Finalization
    • What is a finalizer?
    • When is it called, or is it called at all?
    • The problem with runFinalizersOnExit()
    • Conclusion


    The finally clause
     

    • Cleanup in case of exceptions
    • finally and its impact on the control flow
    • The problem of exception hiding
    Reference Objects 
    • The concept of reachability
    • The concept of reference objects and reference queues
    • The problem of unwanted references and how weak references solve it
    • Caches and soft references
    • Phantom references vs. finalizers
 
 
PREREQUISITES

 
Level: intermediate
Duration: 3 hours
Prerequisites: Attendants should be familiar with the basic concepts of Java.
Presented at: OOPSLA 2000 , Minneapolis, MN, October 2000
DevWeek Europe 2001 , London, UK, Feburary 2001


SOURCE CODE


If you are interested to hear more about this and related topics you might want to check out the following seminar or skim through some further reading:
Seminars
Effective Java 
4 day seminar 
(open enrollment and on-site)
 
Paper
Really Understanding Java -
Myths and Truths Comparing C++ and Java
short white paper (providing first insights)
 

 

  © Copyright 1995-2005 by Angelika Langer.  All Rights Reserved.    URL: < http://www.AngelikaLanger.com/Conferences/Abstracts/SoftWeakReferences.htm  last update: 10 Nov 2005