Skip to content

Commit 1d95619

Browse files
committed
Update README.md
1 parent 7aa3eda commit 1d95619

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

README.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3834,7 +3834,72 @@ app.listen(3000, () => {
38343834
<b><a href="#table-of-contents">↥ back to top</a></b>
38353835
</div>
38363836

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.0 ms (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.0 ms (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.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
3873+
3874+
3875+
<--- JS stacktrace --->
3876+
3877+
FATAL ERROR: invalid array length Allocation failed - JavaScript heap out of memory
3878+
1: 00007FF784AA052F napi_wrap+109311
3879+
2: 00007FF784A45256 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfElementsOffset+33302
3880+
3: 00007FF784A46026 node::OnFatalError+294
3881+
4: 00007FF78531163E v8::Isolate::ReportExternalAllocationLimitReached+94
3882+
5: 00007FF7852F64BD v8::SharedArrayBuffer::Externalize+781
3883+
6: 00007FF7851A094C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1516
3884+
7: 00007FF7851C547F v8::internal::Factory::NewUninitializedFixedArray+111
3885+
8: 00007FF78508B3C0 v8::Object::GetIsolate+8128
3886+
9: 00007FF784F151F7 v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+169671
3887+
10: 00007FF785399FED v8::internal::SetupIsolateDelegate::SetupHeap+463949
3888+
11: 000003EC8D443246
3889+
```
3890+
3891+
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=2048 index.js
3897+
```
3898+
3899+
<div align="right">
3900+
<b><a href="#table-of-contents">↥ back to top</a></b>
3901+
</div>
3902+
38383903
#### Q. What are the types of memory leaks in node.js
38393904

38403905
<div align="right">

0 commit comments

Comments
 (0)