简体   繁体   English

捕获单页应用程序的JavaScript内存泄漏

[英]Catch JavaScript Memory Leak of a Single Page Application

I created a single page application using knockout.js and other map, grid opensource libraries. 我使用基因敲除.js和其他地图,网格开源库创建了一个单页应用程序。

I notice I have memory leak because when I close a "soft" page I have, the Heap Snapshot of latest Chrome indicates my objects are still in memory. 我注意到内存泄漏,因为当我关闭一个“软”页面时,最新的Chrome的堆快照表明我的对象仍在内存中。

I have many situation like Object A subscribe Object B, Object B subscribe Object A, objects are referencing each other. 我有很多情况,例如对象A订阅对象B,对象B订阅对象A,对象相互引用。 Which means, I think, if one of them can't be garbage collected, none of them will be collected. 我认为,这意味着如果其中之一无法被垃圾回收,则将不会进行任何回收。

However, I think even though my Objects are referencing each other "internally", as long as they all inaccessible, they will be collected by garbage collector. 但是,我认为即使我的对象“内部”互相引用,只要它们都无法访问,它们就会被垃圾收集器收集。 The reason my objects are not collected is because I have some "external" reference like $(window).resize(function(){A.something()}) or window.A=A, I believe the key to get rid of memory leak is to find those "external" references. 我的对象没有被收集的原因是因为我有一些“外部”引用,例如$(window).resize(function(){A.something()})或window.A = A,我相信摆脱的关键内存泄漏是为了找到那些“外部”引用。

My questions is how to QUICKLY find those "external" reference using tools like Chrome Heap Snapshot? 我的问题是如何使用Chrome Heap Snapshot等工具快速找到那些“外部”参考? In other words, how to find the key Retainer, for example, A retains B, B retains A, C retains B, in this case, C is the key Retainer, get rid of relation between B and C will make both A and B get garbage collected. 换句话说,如何找到密钥保持器,例如,A保留B,B保留A,C保留B,在这种情况下,C是密钥保持器,摆脱B和C之间的关系会使A和B都收集垃圾。

BTW: Is Dominator View still exist for heap snapshot in Chrome 38 and up? 顺便说一句:Chrome 38及更高版本中的堆快照是否仍存在Dominator View?

There is the answer to you question Tool to track down JavaScript memory leak 有一个问题的答案工具,用于跟踪JavaScript内存泄漏

Also you could read the documentation here 您也可以在这里阅读文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM