Class Jdk8Cleaner

    • Method Detail

      • registerWithOneShotCleaner

        public static void registerWithOneShotCleaner​(Object obj,
                                                      Runnable cleanupTask)
        Creates a new cleaner, and registers the given cleanup action to run when the given object becomes phantom reachable.

        The cleaner's thread terminates after the given cleanup task is executed.

        The cleaning action should generally not be a lambda, since it's easy to accidentally capture a reference to the object, preventing it from ever becoming phantom reachable.

      • register

        public Jdk8Cleaner.Cleanable register​(Object obj,
                                              Runnable cleaningAction)
        Executes the given cleaning action when the object becomes phantom reachable.

        The cleaning action should generally not be a lambda, since it's easy to accidentally capture a reference to the object, preventing it from ever becoming phantom reachable.