From 76c5ca4e1a170d6c7e555c73f9011f01614ebb2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=99=BA=E6=9D=B0?= Date: Wed, 10 Sep 2025 14:45:18 +0800 Subject: [PATCH] Auto Finalizer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: https://gitee.com/openharmony/commonlibrary_ets_utils/issues/ICWWE8?from=project-issue Signed-off-by: 刘智杰 --- api/@ohos.util.d.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/api/@ohos.util.d.ts b/api/@ohos.util.d.ts index 68a7d58965..3d6a0cef6a 100644 --- a/api/@ohos.util.d.ts +++ b/api/@ohos.util.d.ts @@ -4945,5 +4945,49 @@ declare namespace util { */ end(chunk?: string | Uint8Array): string; } + /** + * Provides an interface that can be implemented for releasing a resource + * which is managed by developers through a developer-defined callback. + * + * @interface AutoFinalizer + * @syscap SystemCapability.Utils.Lang + * @crossplatform + * @atomicservice + * @since 22 + */ + interface AutoFinalizer { + /** + * The developer-defined callback used to release resources. + * + * @param { T } heldValue - The value to pass to the finalizer. + * @syscap SystemCapability.Utils.Lang + * @crossplatform + * @atomicservice + * @since 22 + */ + onFinalization(heldValue: T): void; + } + /** + * A cleaner for releasing resources managed by developers through a developer-defined callback. + * + * @syscap SystemCapability.Utils.Lang + * @crossplatform + * @atomicservice + * @since 22 + */ + class AutoFinalizerCleaner { + /** + * Register objects that release resources managed by developers. + * + * @param { AutoFinalizer } obj - The object is registered to the cleaner. + * @param { T } heldValue - The value to pass to the finalizer. + * @static + * @syscap SystemCapability.Utils.Lang + * @crossplatform + * @atomicservice + * @since 22 + */ + static register(obj: AutoFinalizer, heldValue: T): void; + } } export default util; -- Gitee