Chrome / Firefox 中的 Javascript 内存使用和调试(雷区)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4673707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript Memory Usage & Debugging in Chrome / Firefox (Minefield)
提问by Chris
I am currently developing an application using Google O3D WebGL framework, and this is the first time I am using JavaScript so intensively. The features are only around 20% complete, but already the application on its own starts off by taking up around 160 meg of memory, whilst leaving the application running it consumes around 200kb per second in Chrome, 2meg in FF; as the screen is refreshed. As I am writing this I have left Chrome 9 running and it has just hit 400 meg of memory usage. I am now crapping myself especially with FF's usage, and I am looking for any really good documentation on optimizing JavaScript, preventing memory leaks, anything that will help me tackle this basically. I would also really appreciate any links to awesome tools that will help me. Thanks in advance.
我目前正在使用 Google O3D WebGL 框架开发应用程序,这是我第一次如此密集地使用 JavaScript。这些功能只完成了大约 20%,但是应用程序本身已经开始占用大约 160 兆内存,而让应用程序运行时它在 Chrome 中每秒消耗大约 200kb,在 FF 中消耗 2meg;随着屏幕刷新。在我写这篇文章的时候,我已经让 Chrome 9 运行了,它的内存使用量刚刚达到 400 兆。我现在特别在 FF 的使用上自责,我正在寻找任何关于优化 JavaScript、防止内存泄漏的非常好的文档,任何可以帮助我基本上解决这个问题的东西。我也非常感谢任何能帮助我的很棒的工具的链接。提前致谢。
Edit: I have come across Mozilla performance toolsbut I need something simple to use, preferably with a GUI, or at least a noob friendly guide. Also a lot of those tools are for linux (I am using Win7) or require purchase / are command line only. + I would really like to see something for Chrome :) but I will accept the answer that provides the most usefull information.
编辑:我遇到过Mozilla 性能工具,但我需要一些简单易用的东西,最好是带有 GUI,或者至少是一个新手友好的指南。还有很多这些工具适用于 linux(我使用的是 Win7)或需要购买/仅是命令行。+ 我真的很想为 Chrome 看到一些东西 :) 但我会接受提供最有用信息的答案。
Edit: Google Chrome's developer tools only report on 10meg of memory usage, unsure where the rest is coming from.
编辑:谷歌浏览器的开发者工具只报告 10meg 的内存使用情况,不确定其余部分来自哪里。
采纳答案by Bob Aman
Have you had a chance to check out Speed Traceryet? That should give you more of what you need I think.
您有机会查看Speed Tracer吗?我认为这应该会给你更多你需要的东西。
With memory usage, you probably want to do a heap profile in the Chrome developer tools under the "Profiles" tab. You can compare multiple heap profiles to get a look at memory usage.
对于内存使用情况,您可能希望在“配置文件”选项卡下的 Chrome 开发人员工具中执行堆配置文件。您可以比较多个堆配置文件以查看内存使用情况。
回答by monkeyboy
According to http://blog.chromium.org/2011/05/chrome-developer-tools-put-javascript.htmlyou can actually use the performance.memory window property within your Javascript to check the effect of sections of code on memory usage.
根据http://blog.chromium.org/2011/05/chrome-developer-tools-put-javascript.html,您实际上可以使用 Javascript 中的 performance.memory 窗口属性来检查代码段对内存的影响用法。
This looks useful to me as interpreting the output of heap snapshots isn't straightforward.
这对我来说很有用,因为解释堆快照的输出并不简单。

