Class WeakPointerScope

java.lang.Object
org.tensorflow.internal.WeakPointerScope
All Implemented Interfaces:
AutoCloseable

public class WeakPointerScope extends Object implements AutoCloseable
A minimalist pointer scope only keeping weak references to its elements.

As opposed to PointerScope, instances of this class will not prevent the garbage collector to free the memory of a pointer that is no longer reachable, even if it has been attached to the scope.

When the scope is closed, all pointers that are still valid will be automatically deallocated while those already garbage-collected will be ignored.

  • Constructor Details

    • WeakPointerScope

      public WeakPointerScope()
  • Method Details

    • attach

      public void attach(Pointer pointer)
      Attach a pointer to this scope.

      Pointers attached to the scope will be automatically freed once the scope is closed, unless they have been already released by the garbage collector

      It this pointer was already attached to this scope, this method has no effect.

      Parameters:
      pointer - pointer to attach
      Throws:
      IllegalStateException - if that scope has already been closed
    • detach

      public void detach(Pointer pointer)
      Detach a pointer from this scope.

      Detaching a pointer from the scope will prevent its memory to be freed when closing the scope.

      If this pointer is not attached to this scope, this method has no effect.

      Parameters:
      pointer - pointer to detach
      Throws:
      IllegalStateException - if that scope has already been closed
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable