org.apache.lucene.util

## Class RefCount<T>

- java.lang.Object
- - org.apache.lucene.util.RefCount<T>

-     public class RefCount<T>
      extends Object

  Manages reference counting for a given object. Extensions can override `release()` to do custom logic when reference counting hits 0.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected T` | `object`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RefCount(T object)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `decRef()` Decrements the reference counting of this object.
    `T` | `get()`
    `int` | `getRefCount()` Returns the current reference count.
    `void` | `incRef()` Increments the reference count.
    `protected void` | `release()` Called when reference counting hits 0.

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

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

- - ### Field Detail

    - #### object

          protected final T object

  - ### Constructor Detail

    - #### RefCount

          public RefCount(T object)

  - ### Method Detail

    - #### release

          protected void release()
                          throws IOException

      Called when reference counting hits 0. By default this method does nothing, but extensions can override to e.g. release resources attached to object that is managed by this class.
      Throws:
        `IOException`

    - #### decRef

          public final void decRef()
                            throws IOException

      Decrements the reference counting of this object. When reference counting hits 0, calls `release()`.
      Throws:
        `IOException`

    - #### get

          public final T get()

    - #### getRefCount

          public final int getRefCount()

      Returns the current reference count.

    - #### incRef

          public final void incRef()

      Increments the reference count. Calls to this method must be matched with calls to `decRef()`.

Copyright © 2000-2024 Apache Software Foundation. All Rights Reserved.