From 12ff368a40e94fbfa79dffcae70f0193b5150bc1 Mon Sep 17 00:00:00 2001
From: Masahiro FUJIMOTO 注: Cleanup callbacks should not be used for essential program logic. 詳しくは Notes on cleanup callbacks を見てください。 コールバックで渡すレジストリを作成します。 次に、 レジストリがオブジェクトへの強い参照を保持すると、目的に反してしまうので、 (レジストリが強い参照を保持していれば、そのオブジェクトは決して回収されない)、強い参照は保持はしません。 オブジェクトの登録を解除したい場合は、三番目の値を渡します。 これは、後でレジストリのレジストリの よくオブジェクト自身が登録解除トークンとして使われ、これは良い結果になります。 ただし、同じオブジェクトである必要はありません。異なるものでも構いません。 Correct use of Here are some specific points that the authors of the WeakRef proposal that FinalizationRegistry is part of included in its explainer document: Garbage collectors are complicated. If an application or library depends on GC cleaning up a FinalizationRegistry or calling a finalizer [cleanup callback] in a timely, predictable manner, it's likely to be disappointed: the cleanup may happen much later than expected, or not at all. Sources of variability include: Some notes on cleanup callbacks: You create the registry passing in the callback: Then you register any objects you want a cleanup callback for by calling the `register` method, passing in the object and a *held value* for it: {{Compat("javascript.builtins.FinalizationRegistry")}}FinalizationRegistry オブジェクトにより、オブジェクトがガベージコレクションで回収されるときにコールバックを要求することができます。解説
-
-FinalizationRegistry は、レジストリに登録されているオブジェクトが回収される (ガベージコレクションされる) 時にクリーンアップコールバックを要求する方法を提供します。(クリーンアップコールバックはファイナライザーと呼ばれることもあります。)const registry = new FinalizationRegistry(heldValue => {
- // ....
-});
-
-
-register メソッドを呼び出して、クリーンアップコールバックを行いたいオブジェクトを登録し、そのオブジェクトと保持値を渡します。registry.register(theObject, "some value");
-
-
-theObject が回収された場合、クリーンアップコールバックは、指定した保持値 (上では "some value") で呼び出される可能性があります。保持値は、プリミティブでもオブジェクトでも、 undefined であっても構いません。保持値がオブジェクトの場合、レジストリはその値への強い参照を保持します (これにより、後でクリーンアップコールバックに渡すことができます)。unregister 関数をコールしてオブジェクトの登録を解除する際に使用する登録解除トークンです。レジストリは、登録解除トークンへの弱い参照のみを保持します。registry.register(theObject, "some value", theObject);
-// ...some time later, if you don't care about `theObject` anymore...
-registry.unregister(theObject);
-
-
-registry.register(theObject, "some value", tokenObject);
-// ...some time later, if you don't care about `theObject` anymore...
-registry.unregister(tokenObject);
-
-
-コンストラクター
-
-
-
-
-FinalizationRegistry オブジェクト生成します。インスタンスメソッド
-
-
-
-
-Avoid where possible
-
-FinalizationRegistry takes careful thought, and it's best avoided if possible. It's also important to avoid relying on any specific behaviors not guaranteed by the specification. When, how, and whether garbage collection occurs is down to the implementation of any given JavaScript engine. Any behavior you observe in one engine may be different in another engine, in another version of the same engine, or even in a slightly different situation with the same version of the same engine. Garbage collection is a hard problem that JavaScript engine implementers are constantly refining and improving their solutions to.
-
-
-
-
-Notes on cleanup callbacks
-
-
-
-
-
-
- FinalizationRegistry instance itself is no longer reachable by JavaScript code.例
-
-Creating a new registry
-
-const registry = new FinalizationRegistry(heldValue => {
- // ....
-});
-
-
-Registering objects for cleanup
-
-registry.register(theObject, "some value");
-
-仕様書
-
-
-
-
-
-
-
-
-
- 仕様書
-
-
-
-{{SpecName('WeakRefs', '#sec-finalization-registry-objects', 'FinalizationRegistry')}}
- ブラウザーの互換性
-
-関連情報
-
-
-
diff --git a/files/ja/web/javascript/reference/global_objects/finalizationregistry/index.md b/files/ja/web/javascript/reference/global_objects/finalizationregistry/index.md
new file mode 100644
index 0000000000..5edff7c2eb
--- /dev/null
+++ b/files/ja/web/javascript/reference/global_objects/finalizationregistry/index.md
@@ -0,0 +1,129 @@
+---
+title: FinalizationRegistry
+slug: Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
+tags:
+ - Class
+ - FinalizationRegistry
+ - JavaScript
+ - Reference
+browser-compat: javascript.builtins.FinalizationRegistry
+translation_of: Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
+---
+{{JSRef}}
+
+**`FinalizationRegistry`** オブジェクトにより、オブジェクトがガベージコレクションで回収されるときにコールバックを要求することができます。
+
+## 解説
+
+`FinalizationRegistry` は、レジストリーに登録されているオブジェクトが*回収*される (ガベージコレクションされる) 時に*クリーンアップコールバック*を要求する方法を提供します。(クリーンアップコールバックは*ファイナライザー*と呼ばれることもあります。)