JavaScript heap out of memory?

HAYWAEL
  • 2
新手上路,请多包涵

在线上使用pm2运行,大概一天多一些会重启一次;

<--- Last few GCs --->

[32740:0x401de90] 113274887 ms: Mark-sweep 17592186044413.9 (69.5) -> 17592186044413.8 (66.0) MB, 66.2 / 0.0 ms  last resort 
[32740:0x401de90] 113274953 ms: Mark-sweep 17592186044413.8 (66.0) -> 17592186044413.5 (66.0) MB, 65.5 / 0.0 ms  last resort 


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x12d795c29891 <JS Object>
    1: stringSlice(aka stringSlice) [buffer.js:~515] [pc=0x27c660658b67](this=0x2f6e3f382311 <undefined>,buf=0x2fe1d2c3c4a1 <an Uint8Array with map 0x18276da32929>,encoding=0x2f6e3f382311 <undefined>,start=0,end=657873)
    2: toString [buffer.js:~569] [pc=0x27c6607c53d5](this=0x2fe1d2c3c4a1 <an Uint8Array with map 0x18276da32929>,encoding=0x2f6e3f382311 <undefined>,start=0x2f6e3f382311 <undefi...
    
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node /root/lhh/server/index.js]
 2: 0x13647ec [node /root/lhh/server/index.js]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node /root/lhh/server/index.js]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node /root/lhh/server/index.js]
 5: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [node /root/lhh/yys/thxd.js]
 6: v8::internal::Factory::NewStringFromUtf8(v8::internal::Vector<char const>, v8::internal::PretenureFlag) [node /root/lhh/yys/thxd.js]
 7: v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::NewStringType, int) [node /root/lhh/yys/thxd.js]
 8: node::StringBytes::Encode(v8::Isolate*, char const*, unsigned long, node::encoding, v8::Local<v8::Value>*) [node /root/lhh/server/index.js]
 9: 0x1380ad6 [node /root/lhh/server/index.js]
10: 0x2b74ea99c785
评论
阅读 3.6k
1 个回答

出现内存溢出的原因也许是因为代码效率不高,或者是由于不正确的引用/使用引起的;
但更常见的原因是 node_modules (例如,hard-source-webpack-plugin )。
这就是导致内存被消耗掉的原因。

参考资料 :

解决方案 :

  • 找出它占用内存的原因并修复它( 例如 node_modules 或一个死循环的代码 )。
  • 设置 max_old_space_size
宣传栏