JavaMemoryModel: Another important finalizer question

From: Bill Pugh (
Date: Mon Apr 19 2004 - 18:56:31 EDT

Consider the following code:

class Foo {
        OutputStream out;
        Foo(File f, byte[] buf) throws Exception {
                OutputStream o = new FileOutputStream(f);
                out = o;
        protected void finalize() throws IOException {

OK, the question is: it is guaranteed that the call to o.write completes
and that all memory accesses that occur during that call happen-before
any code in the finalizer?

In the spec, we say
        An object cannot be considered finalizable until its constructor has
But we do not say that all writes that occur during construction must
be visible
to the finalizer.

It really doesn't make sense to have one without the other, so I think
is just tightening things up. Let me know if anyone thinks this needs
discussion. Otherwise, we'll just clear up the language and adopt it.


JavaMemoryModel mailing list -

This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:05 EDT