I am trying to understand FinalizationRegistry in JavaScript. As per the MDN docs the FinalizationRegistry callback function will be called as soon as the object it is weakly referencing is lost. I tried with a simple example but doesn't seem to work.
const obj = {a:'GC'}
registry = new FinalizationRegistry(value => {
console.log(value);
});
registry.register(obj, "Garbage collected");
delete obj; //deletes obj from the global context, but FinalizationRegistry registry callback not called
Can someone please give a simple working example?