1

我使用 requireJS 在我的 html5 单页 Web 应用程序中动态加载 JS 模块。我只是想知道我是否应该在完成它们后处理 requireJS 加载的模块(以便垃圾收集器可以清理它们)?如果是这样,那么您如何从 requireJS 中处理所需的模块?

提前致谢

4

1 回答 1

4

It is possible to undefine a module:

There is a global function, requirejs.undef(), that allows undefining a module. It will reset the loader's internal state to forget about the previous definition of the module. However, it will not remove the module from other modules that are already defined and got a handle on that module as a dependency when they executed. So it is really only useful to use in error situations when no other modules have gotten a handle on a module value, or as part of any future module loading that may use that module. See the errback section for an example. If you want to do more sophisticated dependency graph analysis for undefining work, the semi-private onResourceLoad API may be helpful.

http://requirejs.org/docs/api.html#undef

I'm not too sure on the internals but in my usage of the lib I've not found it necessary to do any manual clean up of modules.

于 2012-10-10T08:50:49.860 回答