I don't know how strict JavaScript garbage collection rules are. This was non-observable for the longest time but FinalizationRegistry now exists which makes cleanup observable. It sounds like basically no guarantees are provided when an object will be cleaned up, so presumably an implementation would be allowed to make optimizations such are proposed where for PHP.
moebrowne•2d ago
> Stateless closures, i.e. those that are static, don't capture any variables and don't declare any static variables, are cached between uses.