kakashi_69_xdK
Denoβ€’2y agoβ€’
7 replies
kakashi_69_xd

Finalization not working

I can't get the gc to run a destructor..
At first I thought that I'm making some kind of mistake here but I don't know where..

I was trying to make a Drop trait
abstract class Drop {
    #registry=new FinalizationRegistry((_)=> this.drop());
    constructor() {
        this.#registery.register(this, "");
    }
    protected abstract drop(): void;
}

class Foo extends Drop {
    protected drop(): void {
        console.log("Foo was dropped");
    }
}

const _foo=new Foo();


Then I tried to copy some code that seemed to work from a conf and also mdn but the destructor was never called..

const obj={ xd: "xd" };

const registry=new FinalizationRegistry (heldValue=> console.log(`${heldValue} was dropped`));

registery.register(obj,obj.xd);
Was this page helpful?