Memory leak with fetching external sources
See original GitHub issueIt seems that externally fetched sources (like js-files) are not properly cleared from memory:
var jsdom = require('jsdom');
function get() {
return new Promise((resolve, reject) => {
jsdom.env({
url: 'http://localhost:3200/some-page-with-js',
features: {
FetchExternalResources: ['script'],
ProcessExternalResources: ['script'],
},
done: (err, window) => {
if (err) {
reject(err);
} else {
window.close();
resolve();
}
},
});
});
}
function recurse(i) {
console.log('recurse', i);
if (i < 10000) {
get().then(x => recurse(i+1));
}
}
recurse(0);
<--- Last few GCs --->
40573 ms: Mark-sweep 1336.1 (1447.4) -> 1337.8 (1447.4) MB, 787.7 / 0 ms [allocation failure] [GC in old space requested].
41390 ms: Mark-sweep 1337.8 (1447.4) -> 1337.8 (1447.4) MB, 816.4 / 0 ms [allocation failure] [GC in old space requested].
42260 ms: Mark-sweep 1337.8 (1447.4) -> 1287.9 (1447.4) MB, 869.9 / 0 ms [last resort gc].
43173 ms: Mark-sweep 1287.9 (1447.4) -> 1334.9 (1447.4) MB, 913.7 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x2a6aadc44a49 <JS Object>
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>)
3: processJavaScript(aka processJavaScript) [/Users/Jasper/Code/Q42/blink/test/functional/node_modules/jsdom/l...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Causes of Memory Leaks in JavaScript and How to Avoid Them
Common Sources of Memory Leaks in JavaScript Code # ... A search for the memory leaks causes is actually a search for programming...
Read more >4 Types of Memory Leaks in JavaScript and How to Get Rid Of ...
The main cause for leaks in garbage collected languages are unwanted references. To understand what unwanted references are, first we need to ...
Read more >Understanding Memory Leaks in Java - Baeldung
A memory leak is bad because it blocks memory resources and degrades system performance over time. If not dealt with, the application will ......
Read more >Memory leak when body is not used · Issue #83 · node-fetch ...
I wanted to test a URL for validity; verifying that it returns a 200 response. Using this code: const fetch = require('node-fetch'); ...
Read more >How to handle a memory leak in an external DLL
Definitely hold that last idea for the absolute last resort. Try to find out what kind of memory or resource is being leaked...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’d like to bump this thread, since I think this is something more generic as it happens also for
jsdom.jsdom()
method. I’ve setup a basic repro with the issue: https://github.com/thymikee/jsdom-leak-repro. Hope it helps someone familiar withjsdom
internals to see what’s going on.Below code is sufficient to retain the
Window
object:This is actual problem that we sometimes experience at Jest, here’s on of the relevant issues: https://github.com/facebook/jest/issues/1893
I have the same issue, going over 1.5GB of memory after about 30 iterations of loading a page, even when calling window.close() after each page load. Also happened when I disabled loading externalResources so I don’t think that’s the issue