Skip to content

module: import unload module strategy #5895

Closed

Description

@yjhjstz

A module always loaded in cache. If we only use once, I recommend add strategy to unload the module.
Like the linux kernel do.

Activity

  1. added
    moduleIssues and PRs related to the module subsystem.
    feature requestIssues requesting new Node.js features.
    on Mar 25, 2016
  2. bnoordhuis commented on Mar 25, 2016

    @bnoordhuis
    Member

    To what purpose?

  3. yjhjstz commented on Mar 26, 2016

    @yjhjstz
    Author

    To reduce memory use. @bnoordhuis

  4. bnoordhuis commented on Mar 26, 2016

    @bnoordhuis
    Member

    I don't think that would make a significant difference. V8 is going to keep the script source in memory anyway.

  5. yjhjstz commented on Mar 26, 2016

    @yjhjstz
    Author

    Maybe V8 can provide API to remove script source. And unload a module and reload is useful for hot patch.

  6. bnoordhuis commented on Mar 26, 2016

    @bnoordhuis
    Member

    V8 uses the script source whenever it optimizes or deoptimizes a function. It's also needed for Function.prototype.toString() and, because a module in node.js is basically one big function, that means it retains the script source in its entirety.

    However, if you want to reload modules, you can do that by manipulating require.cache.

  7. SEAPUNK commented on Mar 26, 2016

    @SEAPUNK

    I've always been under the impression that require.cache was an undocumented part of require, but I just now found it, my bad.

  8. coreyleelarson commented on Mar 26, 2016

    @coreyleelarson

    Does import cache modules any differently than require? I always thought it was just syntactic sugar over require. I'm attempting to reload modules on file change and clearing the require.cache only seems to work when I use require on the module.

  9. SEAPUNK commented on Mar 26, 2016

    @SEAPUNK

    @coreyleelarson If you transpile your modules with Babel, babel converts import into require(), because node currently doesn't support ES6 modules just yet.

  10. coreyleelarson commented on Mar 26, 2016

    @coreyleelarson

    @SEAPUNK It must be something else I'm doing wrong, then.

  11. jasnell commented on May 17, 2016

    @jasnell
    Member

    -1 on this, given that the discussion seems to have dropped off, closing. Can reopen if necessary.

  12. naturalethic commented on May 31, 2018

    @naturalethic

    Let's re-open. This issue is quite old, however with ES6 modules now, one may desire to invalidate a module that has changed during development. I haven't found any documentation of this feature, only this ticket.

  13. devsnek commented on May 31, 2018

    @devsnek
    Member

    @naturalethic you can go check if an issue on https://github.com/nodejs/modules doesn't already include this and then open one there.

  14. alshdavid commented on Jun 9, 2020

    @alshdavid

    I need this to test a file that has an IIFE on the top level

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.moduleIssues and PRs related to the module subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions