You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+66-1Lines changed: 66 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3834,7 +3834,72 @@ app.listen(3000, () => {
3834
3834
<b><a href="#table-of-contents">↥ back to top</a></b>
3835
3835
</div>
3836
3836
3837
-
#### Q. How to solve "Process out of Memory Exception" in Node.js?
3837
+
## Q. How to solve "Process out of Memory Exception" in Node.js?
3838
+
3839
+
Process out of Memory Exception is an exception that occurs when your node.js program gets out of memory. This happens when the default memory allocated to our program gets exceeded by our program while execution.
3840
+
3841
+
This exception can be solved by increasing the default memory allocated to our program to the required memory by using the following command.
3842
+
3843
+
**Syntax:**
3844
+
3845
+
```js
3846
+
node --max-old-space-size=<SPACE_REQD>index.js
3847
+
```
3848
+
3849
+
**Example:**
3850
+
3851
+
```js
3852
+
/**
3853
+
* ProcessOutOfMemory Exception
3854
+
*/
3855
+
let items = [];
3856
+
3857
+
for (let i =0; i <999999999; i++) {
3858
+
items.push(i);
3859
+
}
3860
+
3861
+
console.log(items);
3862
+
```
3863
+
3864
+
Output:
3865
+
3866
+
```js
3867
+
<--- Last few GCs --->
3868
+
3869
+
[11652:000001DA4373BE50] 581 ms: Scavenge 765.9 (799.0) ->765.9 (799.0) MB, 29.6/0.0ms (average mu =1.000, current mu =1.000) allocation failure
3870
+
[11652:000001DA4373BE50] 844 ms: Scavenge 1148.4 (1181.6) ->1148.4 (1181.6) MB, 44.7/0.0ms (average mu =1.000, current mu =1.000) allocation failure
3871
+
3872
+
[11652:000001DA4373BE50] 1239 ms: Scavenge 1722.2 (1755.4) ->1722.2 (1755.4) MB, 67.5/0.0ms (average mu =1.000, current mu =1.000) allocation failure
3873
+
3874
+
3875
+
<---JS stacktrace --->
3876
+
3877
+
FATALERROR: invalid array length Allocation failed - JavaScript heap out of memory
The default memory allocated to a node.js program is 512MB on 32-bit systems and 1024MB on 64-bit systems. In the below example, we have increased the memory space requirements to 2048MB or 2GB. Use the following command to run the JS file(index.js).
3892
+
3893
+
**Example:**
3894
+
3895
+
```js
3896
+
node --max-old-space-size=2048index.js
3897
+
```
3898
+
3899
+
<divalign="right">
3900
+
<b><a href="#table-of-contents">↥ back to top</a></b>
3901
+
</div>
3902
+
3838
3903
#### Q. What are the types of memory leaks in node.js
0 commit comments