Class AutoScope
java.lang.Object
smile.util.AutoScope
- All Implemented Interfaces:
AutoCloseable
AutoScope allows for predictable, deterministic resource deallocation.
AutoScope can be closed explicitly or be best used with try-with-resources
statement. Closing an AutoScope will cause all the resources
associated with that scope to be closed.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends AutoCloseable>
Tadd(T resource) Adds resource to this scope.voidclose()voidremove(AutoCloseable resource) Detaches a resource from this scope by reference identity.
-
Constructor Details
-
AutoScope
Constructors.- Parameters:
resources- the resources to be added to this scope.
-
-
Method Details
-
add
Adds resource to this scope.- Type Parameters:
T- the type of resource.- Parameters:
resource- the resource to be added to this scope.- Returns:
- the resource object.
-
remove
Detaches a resource from this scope by reference identity.Must not use
Object.equals(Object):Tensor.equalscompares native handle addresses, so after a closed tensor's address is reused by a new allocation,List.remove(Object)can detach the wrong entry and leave the live tensor on the scope to be freed byclose().- Parameters:
resource- the resource to detach.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-