[concurrency-interest] Object finalization

Chris Vest mr.chrisvest at gmail.com
Sun May 13 16:22:21 EDT 2012


Hi,
I could not find any resources that I felt were clear and trustworthy
enough, so...

I would like to have confirmed (or busted) my assumption that the following
code is buggy, because the garbage collector might set the `a` field to
null, before this `finalize` method can read it, thus preventing the method
from attempting to cleanly dispose of the `Resource` in the `b` field —
this all under the assertion that `safelyDispose` itself never throws:

public class SomeService {
  private final Resource a, b;

  public SomeService(Resource a, Resource b) {
    assert a != null && b != null;
    this.a = a;
    this.b = b;
  }
  @Override
  protected void finalize() throws Throwable {
    a.safelyDispose();
    b.safelyDispose();
  }
}

Cheers,
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20120513/a893b2c7/attachment.html>


More information about the Concurrency-interest mailing list