I am using dynamic import to load scripts written by the user in the browser. I start by placing the script contents into a blob, then I use dynamic import()
to load the script as a module. Over time, I expect these scripts to change and be destroyed, and thus for the corresponding modules to be garbage collected. However, based on memory profiling in Chrome, that is not happening.
The reason why seems to be related to something called the ModuleMap
. Here's a screenshot from a memory snapshot I took after all scripts were no longer in use.
As you can see, the Window object is is providing a retaining path down to these modules. As long as that is the case, I'm sure to eventually run out of memory, since these modules are created each time the user edits their script.
I'd like to know if there's a way to get Chrome (and other browsers) to unload these modules once they are no longer in use.