-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed
Labels
consoleIssues and PRs related to the console subsystem.Issues and PRs related to the console subsystem.duplicateIssues and PRs that are duplicates of other issues or PRs.Issues and PRs that are duplicates of other issues or PRs.memoryIssues and PRs related to the memory management or memory footprint.Issues and PRs related to the memory management or memory footprint.
Description
I'm using NodeJS 4.1.1, 64-bit on Windows 10.
In my simple application I'm calculating a sequence of primes and writing them into the console.
Here's the entire application:
function nextPrime(value) {
if (value > 2) {
var i, q;
do {
i = 3;
value += 2;
q = Math.floor(Math.sqrt(value));
while (i <= q && value % i) {
i += 2;
}
} while (i <= q);
return value;
}
return value === 2 ? 3 : 2;
}
var value;
for (var i = 0; i < 1000000000; i++) {
value = nextPrime(value);
console.log(value);
}
However, when running it, the application starts eating up memory quite fast. I don't understand why, since I am making no memory allocation of any kind, it is just a plain calculation algorithm without any complexity.
After running it for about 5 mins, the app crashes as shown below, before it even gets to calculate the first 100m primes.
98857459
98857469
98857483
98857523
98857531
98857547
<--- Last few GCs --->
287726 ms: Scavenge 1400.7 (1456.6) -> 1400.7 (1456.6) MB, 2.7 / 0 ms (+ 0.0 m
s in 1 steps since last GC) [allocation failure] [incremental marking delaying m
ark-sweep].
288428 ms: Mark-sweep 1400.7 (1456.6) -> 1391.7 (1456.6) MB, 705.4 / 0 ms (+ 0
.0 ms in 2 steps since start of marking, biggest step 0.0 ms) [last resort gc].
289131 ms: Mark-sweep 1391.7 (1456.6) -> 1391.9 (1456.6) MB, 706.8 / 0 ms [las
t resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0000025754B37349 <JS Object>
1: formatPrimitive(aka formatPrimitive) [util.js:~386] [pc=000001A41133E1E3]
(this=0000025754B04131 <undefined>,ctx=0000025754BFFE29 <an Object with map 000
000CA21A4B6F1>,value=98857573)
2: formatValue(aka formatValue) [util.js:213] [pc=000001A4113219BB] (this=00
00025754B04131 <undefined>,ctx=0000025754BFFE29 <an Object with map 000000CA21A4
B6F1>,value=98857573,recurseTimes=2)
3: ...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
efkan, webmarketing45, Masterxilo, amirarcs, pito-svk and 1 morewebmarketing45 and 0ss
Metadata
Metadata
Assignees
Labels
consoleIssues and PRs related to the console subsystem.Issues and PRs related to the console subsystem.duplicateIssues and PRs that are duplicates of other issues or PRs.Issues and PRs that are duplicates of other issues or PRs.memoryIssues and PRs related to the memory management or memory footprint.Issues and PRs related to the memory management or memory footprint.