Question

Im using requireJS to dynamically load JS modules in my html5 single page web application. Im just wanting to know whether I should dispose of the requireJS loaded modules once i have finished with them (so the garbage collector can clean them up)? And if so than how do you dispose a required module from requireJS?

Thanks in advance

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top