javascript - Node js 中服务器执行期间的内存状态

标签 javascript node.js

我是在 Node js 中设计服务器的新手

我知道 Node js 在单个进程中运行,

我的疑问是

1)函数执行后局部变量的内存状态是否仍被存储 - 例如:函数可能会启动一些异步方法,即使在函数执行之后,其回调也会使用这些变量。

所以假设上述情况为真

2)每次调用(服务器网址)时,都会使用请求、响应变量来调用回调。因此内存状态必须不断增加(因为每个 url 调用的内存状态都会被存储,即因为回调 onRequest 中变量的状态) (请求,响应)被存储),因此它应该在某个时间点由于内存不足而崩溃。这种情况会发生吗?

最佳答案

Is the memory state of local variables of a function stored even after its execution

是的。这称为 closure 。只要您的回调处于事件状态,其范围内的变量就可用。

everytime the (server url) is called its callback is called with request,response variables.So the memory state must be continuosly increasing and therefore it should crash at some point of time due to lack of memory.

没有。当所有工作完成后,并且不再有未完成的(异步)回调引用您的变量,它们将是 garbage collected .

Does this happen?

是的,您可能会编写导致内存泄漏的错误代码。

关于javascript - Node js 中服务器执行期间的内存状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24688588/

相关文章:

javascript - HTML Canvas : Replace the Shapes with Numbers (ctx)

javascript - console.log 如何格式化 Json 对象有一个名称吗?

node.js - 我应该将 API key 引用和环境文件放在 Node.js 应用程序中的哪里?

javascript - 带有 JS 的 TypeORM

javascript - 如何使用 winston 记录器在末尾附加日期和时间?

javascript - 电话间隙签名抽奖

javascript - 对象不支持属性或方法 'entries'

mysql - 用于 Restful API 的 Rails 或 node.js

javascript - 用于 jQuery/Javascript 的现代 KVO 库?

Node.js 简单 Google API 请求 : error:0906D06C:PEM routines:PEM_read_bio:no start line