RE: JavaMemoryModel: Finalization idioms

From: Bart Jacobs (
Date: Tue May 03 2005 - 15:03:33 EDT

The motivation usually given for GC.KeepAlive in .NET is the following

class File{
    IntPtr handle;

    extern void NativeWrite(IntPtr handle, byte b);

    extern void NativeFree(IntPtr handle);

    public void Write(byte b){
        NativeWrite(this.handle, b);


Without the KeepAlive call, the object might be considered unreachable at
the start of the NativeWrite call, which might cause the handle to be freed
concurrently with the NativeWrite call.

It's not always recognized, but I think this is just a special case of what
this list talks about.


-----Original Message-----
[] On Behalf Of Boehm, Hans
Sent: Tuesday, May 03, 2005 11:00 AM
To: Thomas Hawtin;
Subject: RE: JavaMemoryModel: Finalization idioms

I think we really need keepAlive in the library. Perhaps java.lang.ref
is a good place to put it. If you implement in the standard
library, with suitable VM cooperation, it should be nearly free.
.NET has GC.KeepAlive which I believe can be used for this purpose,
though the primary motivation there seems to be different.


JavaMemoryModel mailing list -

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