Jika implementasi delegasi menyimpan resource atau memori tambahan yang harus dibebaskan secara eksplisit, praktik terbaik adalah menambahkan metode close() ke implementasi tersebut dan meminta klien memanggilnya secara eksplisit saat instance delegasi tidak lagi digunakan. Meskipun pendekatan ini secara teknis memungkinkan berbagi satu instance delegasi ke beberapa instance penafsir, implementasi delegasi harus mendukung hal ini secara eksplisit.
Menampilkan nama sebutan channel native ke implementasi delegasi TensorFlow Lite.
Metode Turunan
Dari antarmuka
java.io.Closeable
abstrak
void
close()
Dari antarmuka
java.lang.AutoCloseable
abstrak
void
close()
Metode Publik
public
void
close()
Menutup delegasi dan melepaskan resource apa pun yang terkait dengannya.
Berbeda dengan metode yang dideklarasikan di antarmuka Closeable dasar, metode ini
tidak menampilkan pengecualian yang diperiksa.
public
abstrak
long
getNativeHandle()
Menampilkan nama sebutan channel native ke implementasi delegasi TensorFlow Lite.
Catatan: Delegate Java mempertahankan kepemilikan instance delegasi native, dan harus memastikan keberadaannya selama durasi penggunaan dengan instance InterpreterApi apa pun.
Catatan: instance delegasi native mungkin tidak dibuat sampai delegasi telah dilampirkan ke penafsir, sehingga metode ini tidak boleh dipanggil sampai penafsir selesai dibuat dengan delegasi ini.
Hasil
Penangan delegasi native. Di C/C++, ini akan menjadi pointer ke 'TfLiteOpaqueDelegate'.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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|-------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------|"]]