Tools for debugging memory leaks in JavaScript [cl

2019-01-10 02:44发布

I have a memory leak issue in a rather complex JavaScript project and am hoping that there are tools that could help me pin-point the cause of the problem.

I have tried the Google Chrome developer tool Profile tab, where I can take snapshots of the HEAP and diff it with previous snapshots (check http://www.youtube.com/GoogleDevelopers#p/c/B9EC47A6AAE4540F/1/OxW1dCjOstE for a jumpstart on that feature).

I can see the memory drain with this tool but from there I can't find a way to detect where the references to my objects are kept (probably in closures).

My question is: What tools do you use for JavaScript memory leak debugging? Is there a tool that could let me see the references and a bit of source code of where they are held?

3条回答
太酷不给撩
2楼-- · 2019-01-10 03:10

Have a look at https://addons.mozilla.org/en-US/firefox/addon/2490/ I have not tried it but it seem to have some good features.

查看更多
疯言疯语
3楼-- · 2019-01-10 03:10

Check this -> http://ejohn.org/blog/deep-tracing-of-internet-explorer/ It works only on IE though

Edit: Link to the product -> http://ajax.dynatrace.com/ajax/en/

查看更多
贪生不怕死
4楼-- · 2019-01-10 03:27

I seem to run into this issue often and never really have a great answer other than selecting smart breakpoints in your javascript. Sometimes there is a tool for your specific situation that can help find the problem, other times for me it is a long process to find the leak.

Look at the Allocation profiler in Chrome DevTools which gives you a UI for your allocations then allowing you to walk back to their retainers.

Here is a good list of leak tools for Mozilla. In addition, there are some screencasts of how to use the tools. In particular, you may be interested in the section on "Post-processing of stack traces" as it mentions being able to get better symbols, and file name/line number information from a stack trace.

If you are ok using Internet Explorer on Windows, here is a JavaScript Memory Leak Detector which may prove useful as well.

Finally, I found this nice tool on github called MemoryLeakChecker after reading a post here, which looks for large data structures and tries to help you pinpoint where you are leaking memory.

Hope this helps and let me know which one (if any) end up helping you. Sorry for the lack of actual hyperlinks, because I have under 10 reputation right now I can't put them all in the post.

查看更多
登录 后发表回答