FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed – JavaScript heap out of memory

Recently I faced a strange issue where I’m not being able to compile my Angular 7.0 application because of the below error message
—————————————————
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed – JavaScript heap out of memory
1: node::DecodeWrite
2: node_module_register
3: v8::internal::FatalProcessOutOfMemory
4: v8::internal::FatalProcessOutOfMemory
5: v8::internal::Heap::MaxHeapGrowingFactor
6: v8::internal::Factory::NewJSPromise
7: v8::internal::interpreter::operator<<
8: v8::internal::NativesCollection<0>::GetScriptsSource
9: v8::internal::NativesCollection<0>::GetScriptsSource
10: v8::internal::NativesCollection<0>::GetScriptsSource
11: 00000044D2784281
—————————————————
I tried to upgrade the nodeJs and Angular version for my app but with no luck.I even tried to increase the RAMs on my development PC and that ddint solve the issue.
In order to solve this issue, you will need to adjust the default nodeJs used spaces by using the following command:
—————————————————-
node –max_old_space_size=8192 node_modules/@angular/cli/bin/ng build –prod –build-optimizer
—————————————————-
Below is the original command that I was using and it was giving me the error in concern
—————————————————-
Ng build –prod –prod-optimizer
—————————————————-