提问人:Itay Bardugo 提问时间:11/10/2023 更新时间:11/10/2023 访问量:33
nodejs 垃圾回收器会释放分配的内存吗?
Will nodejs garbage collector free the allocated memory?
问:
我正在开发一个 nestjs 应用程序。 众所周知,NestJS 有其依赖注入。 如果我使用 Nesjs DI 创建一个服务(我们称之为 ExternalServicrClient),并且该服务是单例, 然后,我将该服务传递到一个类中 - 我们将其称为 FetchSomething,使用新的 FetchSomething() 方式(在 Nest DI 系统之外)
垃圾收集器会在 FetchSomething 结束时释放分配的内存吗? 例:
Class FetchSomething{
Private e
xternalServicrClient :ExternalServicrClient
Constructor(service) {
This.externalServicrClient = service
}
DoSomething() {
Return This.externalServicrClient.request()
}
}
Class facade{
Function start(){
Instance = new FetchSomething(
Service=this.externalServiceClient
)
Instance.DoSomething()
}
}
还没有检查过
答: 暂无答案
评论
FetchSomething
start()
DoSomething
FetchSomething
是普通对象,当没有可访问的引用时,将有资格进行垃圾回收。事实上,它引用了其他不会被GC的东西,这对>它的一生<无关紧要。