اگر یک پیاده سازی delegate منابع یا حافظه اضافی را در خود جای دهد که باید به طور صریح آزاد شوند، بهترین روش این است که یک متد close() را به پیاده سازی اضافه کنید و زمانی که نمونه delegate دیگر استفاده نمی شود، از کلاینت بخواهید آن را صریحاً فراخوانی کند. در حالی که این رویکرد از نظر فنی امکان اشتراکگذاری یک نمونه نماینده واحد را در چندین نمونه مفسر میدهد، پیادهسازی نماینده باید صریحاً از این پشتیبانی کند.
یک دسته بومی را به پیادهسازی نماینده TensorFlow Lite برمیگرداند.
روش های ارثی
از رابط java.io.Closeable
خلأ انتزاعی
بستن ()
از رابط java.lang.AutoCloseable
خلأ انتزاعی
بستن ()
روش های عمومی
بسته شدنفضای خالی عمومی()
نماینده را می بندد و منابع مرتبط با آن را آزاد می کند.
بر خلاف روش اعلام شده در رابط پایه Closeable ، این روش استثناهای بررسی شده را پرتاب نمی کند.
انتزاع عمومی طولانیgetNativeHandle()
یک دسته بومی را به پیادهسازی نماینده TensorFlow Lite برمیگرداند.
توجه: Delegate جاوا مالکیت نمونه نماینده بومی را حفظ می کند و باید از وجود آن در طول مدت استفاده با هر نمونه InterpreterApi اطمینان حاصل کند.
توجه: نمونه نماینده بومی ممکن است ایجاد نشود تا زمانی که نماینده به یک مترجم متصل نشده باشد، بنابراین این روش نباید تا زمانی که یک مفسر با این نماینده ساخته شده است فراخوانی شود.
برمی گرداند
دسته نماینده بومی. در C/C++، این باید نشانگر «TfLiteOpaqueDelegate» باشد.
تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی."],[],[],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|-------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------|"]]