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
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:
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.