从 Node.js 释放所需的模块 [英] Release required module from Node.js

查看:27
本文介绍了从 Node.js 释放所需的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在运行时释放 Node.js 模块以节省内存或提高整体性能.

How can one release a Node.js module during runtime in order to save memory or improve the overall performance.

我的应用程序在运行时动态加载 Node.js 中的模块,但不卸载任何模块.我正在寻找这样的功能,尤其是.在代码加载模块后更新已更改的模块;以及卸载可能不再使用的模块.

My application dynamically loads modules in Node.js during runtime, but does not unload any of them. I'm looking for such functionality esp. to update a module that has been changed after the code loaded the module; and also to unload modules that may not be used further.

有什么见解吗?

谢谢.

推荐答案

听起来您正在创建某种插件系统.我会看看节点虚拟机的:http://nodejs.org/docs/latest/api/vm.html

It sounds like you're creating some sort of plugin system. I would have a look at Node VM's: http://nodejs.org/docs/latest/api/vm.html

它允许您在沙箱中加载和运行代码,这意味着当它完成时,它的所有内部分配都应该再次释放.

It allows you to load and run code in a sandbox which means when it's finished all it's internal allocations should be freed again.

它被标记为不稳定,但这并不意味着它不起作用.这意味着 API 可能会在 Node 的未来版本中发生变化.

It is marked as unstable, but that doesn't mean it doesn't work. It means the API might change in future versions of Node.

例如,基于节点的 smtp 服务器 Haraka 使用 VM 模块(重新)加载插件.

As an example, Haraka, a node based smtp server, uses the VM module to (re)load plugins.

这篇关于从 Node.js 释放所需的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆