org.h2.util

## Class CloseWatcher

- java.lang.Object
- - java.lang.ref.Reference<T>
  - - java.lang.ref.PhantomReference<java.lang.Object>
    - - org.h2.util.CloseWatcher

    public class CloseWatcher
    extends java.lang.ref.PhantomReference<java.lang.Object>

A phantom reference to watch for unclosed objects.

### Constructor Summary

Constructors
Constructor and Description
`CloseWatcher(java.lang.Object referent, java.lang.ref.ReferenceQueue<java.lang.Object> q, java.io.Closeable closeable)`

### Method Summary

Methods
`java.io.Closeable` `getCloseable()`
`java.lang.String` `getOpenStackTrace()` Get the open stack trace or null if none.
`static CloseWatcher` `pollUnclosed()` Check for an collected object.
`static CloseWatcher` `register(java.lang.Object o, java.io.Closeable closeable, boolean stackTrace)` Register an object.
`static void` `unregister(CloseWatcher w)` Unregister an object, so it is no longer tracked.

### Methods inherited from class java.lang.ref.PhantomReference

`get`

### Methods inherited from class java.lang.ref.Reference

`clear, enqueue, isEnqueued`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### CloseWatcher

    public CloseWatcher(java.lang.Object referent,
                java.lang.ref.ReferenceQueue<java.lang.Object> q,
                java.io.Closeable closeable)

### Method Detail

#### pollUnclosed

    public static CloseWatcher pollUnclosed()

Check for an collected object.

Returns:
  the first watcher

#### register

    public static CloseWatcher register(java.lang.Object o,
                        java.io.Closeable closeable,
                        boolean stackTrace)

Register an object. Before calling this method, pollUnclosed() should be called in a loop to remove old references.

Parameters:
  `o` - the object
  `closeable` - the object to close
  `stackTrace` - whether the stack trace should be registered (this is relatively slow)
Returns:
  the close watcher

#### unregister

    public static void unregister(CloseWatcher w)

Unregister an object, so it is no longer tracked.

Parameters:
  `w` - the reference

#### getOpenStackTrace

    public java.lang.String getOpenStackTrace()

Get the open stack trace or null if none.

Returns:
  the open stack trace

#### getCloseable

    public java.io.Closeable getCloseable()