Angular 通过 DebugElement 发生内存泄漏 - 如何在生产模式下 运行 不混淆?

Angular Memory Leak via DebugElement - How to run in production mode without obfuscation?

我正在解决内存泄漏问题,已经删除了常用主题(订阅)。在内存快照中查看我的组件的未收集实例时,它们都是通过引导 DebugElement 对象的路径保留的。

component in Object@10648105
_parentView in TemplateRef_@10653347core.js:21737
cellTemplate in Object@10684619
[24] in Array@10689419
oldValues in Object@10655939
elView in DebugContext_@10687621core.js:24015
_debugContext in DebugElement__PRE_R3__@10691153
...

当使用 ng serve --prod 时,应用程序仍然会泄漏内存,但由于混淆,我无法在快照中找到我的 class 的实例。

有没有办法在不混淆代码的情况下关闭调试模式?

对于 main.ts 中的 Angular CLI 应用程序,您有以下几行:

if (environment.production) {
  enableProdMode();
}

您可以删除始终启用生产模式的条件。

我也遇到过同样的情况,DebugContext 保留了一些组件实例。在生产模式下,实例已正确清理。