Se un'implementazione delegata contiene risorse o memoria aggiuntive che devono essere liberate esplicitamente, la best practice consiste nell'aggiungere un metodo close() all'implementazione e fare in modo che il client lo chiami in modo esplicito quando l'istanza delegata non è più in uso. Sebbene questo approccio consenta tecnicamente la condivisione di una singola istanza del delegato tra più istanze dell'interprete, l'implementazione del delegato deve supportarla esplicitamente.
Restituisce un handle nativo all'implementazione delegata di TensorFlow Lite.
Metodi ereditati
Dall'interfaccia
java.io.Closeable
astratto
void
close()
Dall'interfaccia
java.lang.AutoCloseable
astratto
void
close()
Metodi pubblici
pubblica
void
chiudi()
Chiude il delegato e rilascia tutte le risorse associate.
A differenza del metodo dichiarato nell'interfaccia di base Closeable, questo metodo non genera eccezioni selezionate.
Public
astratto
long
getNativeHandle()
Restituisce un handle nativo all'implementazione delegata di TensorFlow Lite.
Nota: Delegate Java mantiene la proprietà dell'istanza del delegato nativo e deve garantirne l'esistenza per la durata di utilizzo con qualsiasi istanza InterpreterApi.
Nota: è possibile che l'istanza nativa del delegato non venga creata finché il delegato non è stato associato a un interprete, quindi questo metodo non deve essere chiamato finché non è stato creato un interprete con questo delegato.
Ritorni
L'handle nativo del delegato. In C/C++, dovrebbe essere un puntatore a
"TfLiteOpaqueDelegate".
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-07-24 UTC."],[],[],null,["# Delegate\n\npublic interface **Delegate** \n\n|---|---|---|\n| Known Indirect Subclasses [GpuDelegate](/edge/api/tflite/java/org/tensorflow/lite/gpu/GpuDelegate) |--------------------------------------------------------------------------|-----------------------------------------------------------------------------------| | [GpuDelegate](/edge/api/tflite/java/org/tensorflow/lite/gpu/GpuDelegate) | [Delegate](/edge/api/tflite/java/org/tensorflow/lite/Delegate) for GPU inference. | |||\n\nWrapper for a native TensorFlow Lite Delegate.\n\nIf a delegate implementation holds additional resources or memory that should be explicitly\nfreed, then best practice is to add a `close()` method to the implementation and have the\nclient call that explicitly when the delegate instance is no longer in use. While this approach\ntechnically allows sharing of a single delegate instance across multiple interpreter instances,\nthe delegate implementation must explicitly support this.\n\n\u003cbr /\u003e\n\n### Public Methods\n\n|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| void | [close](/edge/api/tflite/java/org/tensorflow/lite/Delegate#close())() Closes the delegate and releases any resources associated with it. |\n| abstract long | [getNativeHandle](/edge/api/tflite/java/org/tensorflow/lite/Delegate#getNativeHandle())() Returns a native handle to the TensorFlow Lite delegate implementation. |\n\n### Inherited Methods\n\nFrom interface java.io.Closeable \n\n|---------------|---------|\n| abstract void | close() |\n\nFrom interface java.lang.AutoCloseable \n\n|---------------|---------|\n| abstract void | close() |\n\nPublic Methods\n--------------\n\n#### public void\n**close**\n()\n\nCloses the delegate and releases any resources associated with it.\n\nIn contrast to the method declared in the base [Closeable](https://developer.android.com/reference/java/io/Closeable.html) interface, this method\ndoes not throw checked exceptions.\n\n\u003cbr /\u003e\n\n#### public abstract long\n**getNativeHandle**\n()\n\nReturns a native handle to the TensorFlow Lite delegate implementation.\n\nNote: The Java [Delegate](/edge/api/tflite/java/org/tensorflow/lite/Delegate) maintains ownership of the native delegate instance, and\nmust ensure its existence for the duration of usage with any [InterpreterApi](/edge/api/tflite/java/org/tensorflow/lite/InterpreterApi) instance.\n\nNote: the native delegate instance may not be created until the delegate has been attached\nto an interpreter, so this method should not be called until after an interpreter has been\nconstructed with this delegate.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n##### Returns\n\n- The native delegate handle. In C/C++, this should be a pointer to 'TfLiteOpaqueDelegate'. \n\n##### Throws\n\n| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException.html) | if called before the native delegate instance has been constructed. |\n|-------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------|"]]