JavaScript · Senior · Question 11 of 75
Why are you advised to be careful with WeakRef and FinalizationRegistry?
- ✓Correct answer: Garbage collection timing is unpredictable - logic shouldn't depend on it
- 2They work only in Node.js and aren't available in browser engines
- 3They slow down access to all objects in the app dozens of times
Explanation
An object behind a WeakRef can disappear at any moment or live longer than expected, and a finalization callback may never be called. They're appropriate for caches and as a safety net, but not for mandatory resource cleanup.