import * as std from "qjs:std";
{
let target = {};
let fr = new FinalizationRegistry(function() {});
fr.register(target, fr);
fr.ref = target;
target.ref = fr;
target = null;
fr = null;
std.gc();
}
{
let target = {};
let cb = function() {};
let fr = new FinalizationRegistry(cb);
fr.register(target, 42);
fr.ref = target;
target.ref = fr;
target.cb = cb;
target = null;
fr = null;
cb = null;
std.gc();
}
{
class Registry {
#fr = new FinalizationRegistry(v => {});
set(key) {
const ref = new WeakRef(key);
this.#fr.register(key, {}, ref);
}
}
function Observer() {
this.targets = new Registry;
}
Observer.prototype.observe = function(target) {
this.targets.set(target);
target.subset = new Set;
target.subset.add(this);
}
let sample = {};
new Observer().observe(sample);
sample = null;
std.gc();
}