Are ES Modules garbage collected? If so, do they re-execute on next import?

Gus Caplan me at gus.host
Wed Jul 1 01:07:00 UTC 2020


Modules in the spec are cached by specifier by modules that import them.
Modules in major implementations are additionally cached for the entire
realm by absolute URLs. I would say that for actual code (functions and
classes and whatnot) leaks aren't really a problem. Even if you import a
ton of levels, that's not that much memory. The main concern I've seen
raised is JSON modules, where once you import them the JSON object, which
can be quite large, will never be collected. Of course, there is a simple
solution to that (fetch) so it isn't a world ending problem.

On Tue, Jun 30, 2020 at 7:41 PM #!/JoePea <joe at trusktr.io> wrote:

> I am curious: can modules be garbage collected if the exports are not
> references by anything anymore? And if so, will the module be
> re-evaluated the next time it is imported?
>
> I haven't tried an experiment to answer this yet. I'll be back to post
> findings if someone doesn't post an official answer first.
>
> I'm thinking about code longevity. For example, if we make
> long-running web-based applications with many routes and features (for
> sake of example imagine a desktop environment, or a MMORPG game, with
> apps or components that are loaded within the same context). Over
> time, if imports are not collected, then it means we have a memory
> leak.
>
> Imagine, for example, an infinite-universe MMORPG where you can land
> on different planets where the code for features of a planet are
> provided by third parties as ES Modules. I know, this might not be a
> safe idea to import any code into an app, but just imagine it for sake
> of example (imagine we have a continuous integration system to test
> and verify code security, or something, before that code is allowed to
> be consumed in the app). Imagine you play this app for many many days,
> and visit many places, and you leave the app running the whole time
> (because farming for resources is disabled if the app is not running,
> or something).
>
> I would imagine that we want unused modules (when we leave a planet,
> for example) to be (destroyed) garbage collected so that we don't
> waste memory.
>
> #!/JoePea
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20200630/10b0bbda/attachment.html>


More information about the es-discuss mailing list