首页 > 解决方案 > 在 nodejs 的底层发生了什么?

问题描述

考虑这段伪代码:

i = 0;
while i < int.maxvalue {
  print(i)
  i += 1
}

在其中运行此代码时,nodejs它开始吃掉我的 RAM 并在 2 GB 处被压碎,而在garbage collector我尝试过的任何其他语言(ruby、python、java)上,它们吃掉了 ~3..~15 MB 的 RAM。

只是为了了解幕后发生的事情,我想问 - 为什么它在 nodejs 中会这样工作?

更新:python上的真实代码:

import sys
i = 0
while i < sys.maxint:
  print(i)
  i += 1

对于节点:

let i = 0;
while(i<Number.MAX_VALUE){
  console.log(i);
  i += 1;
}

标签: node.js

解决方案


推荐阅读