Angular 2+路由器是否卸载先前的延迟加载模块 [英] Does the Angular 2+ Router Unload the Previous Lazy Loaded Module

查看:51
本文介绍了Angular 2+路由器是否卸载先前的延迟加载模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究大量ngModule,每个ngModule封装了自己的一组组件,服务,指令等.它们很大.现在,我准备将应用程序串起来,然后将每个模块延迟地路由到主路由器出口上,我担心总体内存消耗,尤其是对于低端设备(仅平板电脑,而不是平板电脑).所以我的问题是,当路由器延迟加载新模块时,先前的延迟加载模块是否已卸载?我只能找到有关JIT,AOT,预加载和延迟加载的信息,但是在后加载的上下文中缺少有关Angular 2+和内存管理的资源或讨论.

I have been working on numerous ngModules, each encapsulating their own set of components, services, directives, etc. They are large. Now that I am ready to string my app up and lazily route each module onto the main router-outlet, I am concerned about overall memory consumption, particularly for low-end devices (tablets on up only, not mobile). So my question is when the Router lazy loads a new module, is the previous lazy loaded module unloaded? I can only find information about JIT, AOT, pre-loading and lazy loading but there is a dearth of resources or discussions about Angular 2+ and memory management in a post-loaded context.

预先感谢您考虑我的问题.

Thank you in advance for considering my question.

推荐答案

我可以确认,尽管最初并未使用惰性加载方法来加载它们,但在路由到另一个模块之后它们并没有被卸载.更糟糕的是ngx将不支持卸载模块.这是向Brad Green提出确切问题的推文.

I can confirm that though they aren't initially loaded using the lazy loading method they are not unloaded after routing to another module. whats worse is unloading modules is not going to be supported by ngx. here is the tweet where this exact question was asked of Brad Green.

https://twitter.com/bunsofaluminum/status/642397294474756096 .

我想添加有关卸载组件的快速注释.您可以卸载组件以及与它们关联的数据,我知道两种方法 DynamicComponentLoader 是核心和

I wanted to add a quick comment about unloading components. you can unload components and the data associated with them there are two ways I know of DynamicComponentLoader which is part of core and OnDestroy which implements just like OnInit . You should be able to leverage both of those to help with overall memory load especially if your using alot of services which you can unsubscribe to OnDestroy.

这篇关于Angular 2+路由器是否卸载先前的延迟加载模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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