Interface ReferenceManager


public interface ReferenceManager
This interface represents managing references to Objects and providing the ability to run a cleaning operation once the object is no longer able to be reference.

Expected usage of this is through INSTANCE.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ReferenceManager
    The global instance of ReferenceManager that should be used to maintain object references.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    register(Object object, Runnable cleanupAction)
    Registers the object and the cleaning action to run once the object becomes phantom reachable.
  • Field Details

  • Method Details

    • register

      void register(Object object, Runnable cleanupAction)
      Registers the object and the cleaning action to run once the object becomes phantom reachable.

      The cleanupAction cannot have a reference to the object, otherwise the object will never be able to become phantom reachable.

      Exceptions thrown by cleanupAction are ignored.

      Parameters:
      object - The object to monitor.
      cleanupAction - The cleanup action to perform when the object becomes phantom reachable.
      Throws:
      NullPointerException - If either object or cleanupAction are null.