{"action":"created","issue":{"url":"https://api.github.com/repos/tmpvar/jsdom/issues/1493","repository_url":"https://api.github.com/repos/tmpvar/jsdom","labels_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1493/labels{/name}","comments_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1493/comments","events_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1493/events","html_url":"https://github.com/tmpvar/jsdom/issues/1493","id":155931568,"number":1493,"title":"Memory leak with fetching external sources","user":{"login":"Jpunt","id":190501,"avatar_url":"https://avatars.githubusercontent.com/u/190501?v=3","gravatar_id":"","url":"https://api.github.com/users/Jpunt","html_url":"https://github.com/Jpunt","followers_url":"https://api.github.com/users/Jpunt/followers","following_url":"https://api.github.com/users/Jpunt/following{/other_user}","gists_url":"https://api.github.com/users/Jpunt/gists{/gist_id}","starred_url":"https://api.github.com/users/Jpunt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jpunt/subscriptions","organizations_url":"https://api.github.com/users/Jpunt/orgs","repos_url":"https://api.github.com/users/Jpunt/repos","events_url":"https://api.github.com/users/Jpunt/events{/privacy}","received_events_url":"https://api.github.com/users/Jpunt/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/tmpvar/jsdom/labels/memory","name":"memory","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-05-20T10:18:55Z","updated_at":"2016-08-31T15:49:20Z","closed_at":null,"body":"It seems that externally fetched sources (like js-files) are not properly cleared from memory:\r\n\r\n```js\r\nvar jsdom = require('jsdom');\r\n\r\nfunction get() {\r\n  return new Promise((resolve, reject) => {\r\n    jsdom.env({\r\n      url: 'http://localhost:3200/some-page-with-js',\r\n      features: {\r\n        FetchExternalResources: ['script'],\r\n        ProcessExternalResources: ['script'],\r\n      },\r\n      done: (err, window) => {\r\n        if (err) {\r\n          reject(err);\r\n        } else {\r\n          window.close();\r\n          resolve();\r\n        }\r\n      },\r\n    });\r\n  });\r\n}\r\n\r\nfunction recurse(i) {\r\n  console.log('recurse', i);\r\n  if (i < 10000) {\r\n    get().then(x => recurse(i+1));\r\n  }\r\n}\r\n\r\nrecurse(0);\r\n```\r\n\r\n```\r\n<--- Last few GCs --->\r\n\r\n   40573 ms: Mark-sweep 1336.1 (1447.4) -> 1337.8 (1447.4) MB, 787.7 / 0 ms [allocation failure] [GC in old space requested].\r\n   41390 ms: Mark-sweep 1337.8 (1447.4) -> 1337.8 (1447.4) MB, 816.4 / 0 ms [allocation failure] [GC in old space requested].\r\n   42260 ms: Mark-sweep 1337.8 (1447.4) -> 1287.9 (1447.4) MB, 869.9 / 0 ms [last resort gc].\r\n   43173 ms: Mark-sweep 1287.9 (1447.4) -> 1334.9 (1447.4) MB, 913.7 / 0 ms [last resort gc].\r\n\r\n\r\n<--- JS stacktrace --->\r\n\r\n==== JS stack trace =========================================\r\n\r\nSecurity context: 0x2a6aadc44a49 <JS Object>\r\n    2: runInContext [vm.js:~42] [pc=0x361d28a9b004] (this=0x2a7ae5198239 <an Object with map 0xb6831c271a9>,code=0xf882304101 <Very long string[4912697]>,contextifiedSandbox=0x31599489d4e9 <a Window with map 0x3e12b0c06bf9>,options=0x1947d74ae761 <an Object with map 0xb6831c3e1d1>)\r\n    3: processJavaScript(aka processJavaScript) [/Users/Jasper/Code/Q42/blink/test/functional/node_modules/jsdom/l...\r\n\r\nFATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory\r\n```\r\n\r\n![screen shot 2016-05-20 at 12 17 42](https://cloud.githubusercontent.com/assets/190501/15424801/de80b902-1e84-11e6-8807-8017bcb49a24.png)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/tmpvar/jsdom/issues/comments/243808476","html_url":"https://github.com/tmpvar/jsdom/issues/1493#issuecomment-243808476","issue_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1493","id":243808476,"user":{"login":"jpiv","id":10170807,"avatar_url":"https://avatars.githubusercontent.com/u/10170807?v=3","gravatar_id":"","url":"https://api.github.com/users/jpiv","html_url":"https://github.com/jpiv","followers_url":"https://api.github.com/users/jpiv/followers","following_url":"https://api.github.com/users/jpiv/following{/other_user}","gists_url":"https://api.github.com/users/jpiv/gists{/gist_id}","starred_url":"https://api.github.com/users/jpiv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpiv/subscriptions","organizations_url":"https://api.github.com/users/jpiv/orgs","repos_url":"https://api.github.com/users/jpiv/repos","events_url":"https://api.github.com/users/jpiv/events{/privacy}","received_events_url":"https://api.github.com/users/jpiv/received_events","type":"User","site_admin":false},"created_at":"2016-08-31T15:49:20Z","updated_at":"2016-08-31T15:49:20Z","body":"+1"}}
{"actor":{"display_login":"jpiv"}}