Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Ability to Delete Modules Again #527

Open
apparebit opened this issue Jun 13, 2020 · 0 comments
Open

Ability to Delete Modules Again #527

apparebit opened this issue Jun 13, 2020 · 0 comments

Comments

@apparebit
Copy link

Based on my own experiments with loader hooks as well as the discussion in nodejs/node#31229 and then #525, I believe that loader hooks are missing the ability to delete modules again. Otherwise, the ESM loader is strictly less expressive than the CommonJS loader, where an existing module cache entry can be trivially null-ed out and the corresponding values can be GC'ed. This may impact other loaders such as for mocking as well, but probably is most important for hot module reloading: In that case, the Node.js process can reasonably be expected to be long-living and a few modules may just be reloaded over and over and over again. Without a hook to release modules again, the process will eventually run out of memory. Yet, that application also knows when a module will never be accessed/executed again, i.e., any module that has been reloaded and whose code has finished executing effectively is garbage already.

I might add that reclamation of unused code has been a problem in Java as well, which first shipped without the ability to garbage collect classes and still suffers from hard-to-debug leaks that prevent class loaders from becoming garbage. That might, btw, suggest an approach for structuring a solution: If loaders can be instantiated at runtime and that operation is lightweight enough, allow garbage collection at granularity of a loader and all loaded modules. But I believe that it should be possible with much less ceremony as well, as the current CommonJS implementation illustrates.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant