I'm not aware of a way to control the GC behavior of an object in JS. The memory will be freed, and that's all. If something else needed to be done, I don't think there's a way to do it. Happy to be proven wrong though.
You can kinda use a WeakMap to later detect if an object has been dereferenced, and thus run some sorta cleanup routine.
How? WeakMap (and WeakSet, more directly) can detect if an object has been collected only if you have a reference to pass to it. If you have reference to the object in a variable or data structure, it won't have been eligible for collection in the first place.
You can't use a WeakMap or a WeakSet, but you can use a WeakRef or a FinalizationRegistry.