{"action":"created","issue":{"url":"https://api.github.com/repos/webpack/webpack/issues/1602","labels_url":"https://api.github.com/repos/webpack/webpack/issues/1602/labels{/name}","comments_url":"https://api.github.com/repos/webpack/webpack/issues/1602/comments","events_url":"https://api.github.com/repos/webpack/webpack/issues/1602/events","html_url":"https://github.com/webpack/webpack/issues/1602","id":115783240,"number":1602,"title":"Is require() wasting memory?","user":{"login":"ronkorving","id":631240,"avatar_url":"https://avatars.githubusercontent.com/u/631240?v=3","gravatar_id":"","url":"https://api.github.com/users/ronkorving","html_url":"https://github.com/ronkorving","followers_url":"https://api.github.com/users/ronkorving/followers","following_url":"https://api.github.com/users/ronkorving/following{/other_user}","gists_url":"https://api.github.com/users/ronkorving/gists{/gist_id}","starred_url":"https://api.github.com/users/ronkorving/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ronkorving/subscriptions","organizations_url":"https://api.github.com/users/ronkorving/orgs","repos_url":"https://api.github.com/users/ronkorving/repos","events_url":"https://api.github.com/users/ronkorving/events{/privacy}","received_events_url":"https://api.github.com/users/ronkorving/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/webpack/webpack/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-11-09T03:10:00Z","updated_at":"2015-11-17T11:16:56Z","closed_at":null,"body":"We're about to start using webpack on a huge (megabytes of JS) project. On a project of that scale, memory use and waste really starts to matter and I was wondering about Webpack. So I dove into the __webpack_require__ function. For reference, here is the code I would like to discuss:\r\n\r\n```js\r\n/******/ \tfunction __webpack_require__(moduleId) {\r\n/******/\r\n/******/ \t\t// Check if module is in cache\r\n/******/ \t\tif(installedModules[moduleId])\r\n/******/ \t\t\treturn installedModules[moduleId].exports;\r\n/******/\r\n/******/ \t\t// Create a new module (and put it into the cache)\r\n/******/ \t\tvar module = installedModules[moduleId] = {\r\n/******/ \t\t\texports: {},\r\n/******/ \t\t\tid: moduleId,\r\n/******/ \t\t\tloaded: false\r\n/******/ \t\t};\r\n/******/\r\n/******/ \t\t// Execute the module function\r\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\r\n/******/\r\n/******/ \t\t// Flag the module as loaded\r\n/******/ \t\tmodule.loaded = true;\r\n/******/\r\n/******/ \t\t// Return the exports of the module\r\n/******/ \t\treturn module.exports;\r\n/******/ \t}\r\n```\r\n\r\nWhat I notice is that once a module's wrapper function has been executed, we'll have the module object cached (makes sense, for the require call). However we also still have the wrapper function (`modules[moduleId]`) which will never ever get executed again, because of the if-statement at the start of the function. So why are we keeping it around? It seems we could reclaim memory by simply assigning `undefined` to `modules[moduleId]`.\r\n\r\nAm I missing something or is this a really easy opportunity to reclaim memory?"},"comment":{"url":"https://api.github.com/repos/webpack/webpack/issues/comments/157340705","html_url":"https://github.com/webpack/webpack/issues/1602#issuecomment-157340705","issue_url":"https://api.github.com/repos/webpack/webpack/issues/1602","id":157340705,"user":{"login":"IngwiePhoenix","id":2893716,"avatar_url":"https://avatars.githubusercontent.com/u/2893716?v=3","gravatar_id":"","url":"https://api.github.com/users/IngwiePhoenix","html_url":"https://github.com/IngwiePhoenix","followers_url":"https://api.github.com/users/IngwiePhoenix/followers","following_url":"https://api.github.com/users/IngwiePhoenix/following{/other_user}","gists_url":"https://api.github.com/users/IngwiePhoenix/gists{/gist_id}","starred_url":"https://api.github.com/users/IngwiePhoenix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IngwiePhoenix/subscriptions","organizations_url":"https://api.github.com/users/IngwiePhoenix/orgs","repos_url":"https://api.github.com/users/IngwiePhoenix/repos","events_url":"https://api.github.com/users/IngwiePhoenix/events{/privacy}","received_events_url":"https://api.github.com/users/IngwiePhoenix/received_events","type":"User","site_admin":false},"created_at":"2015-11-17T11:16:56Z","updated_at":"2015-11-17T11:16:56Z","body":"A game compiled by webpack?\n… You seriously should let us know of a beta, it’d be nice to link to something like that as a usecase :)\n\nAnyway BTT:\n\nWhen you have some results, post them here. Then, you can try to remove the function by setting it to NULL or undefined and re-test. See if that changed something and how much."}}