How to measure memory usage and efficiency?

不羁岁月 提交于 2019-12-18 19:05:07

问题


I have a web app that uses a lot of JavaScript and is intended to run non-stop (for days/weeks/months) without a page reload.

However, Chrome is crashing after a few hours. Safari doesn't crash as often, but it does slow down considerably.

How can I check whether or not the issues are with my code, or with the browser itself? And what can I do to resolve these issues?


回答1:


Using Chrome Developer Profile Tools you can get a snapshot of what's using your CPU and get a memory snapshot.

Take 2 snaps shots. Select this first one and switch to comparison as shown below

The triangle column is the mathmatical symbol delta or change. So if your deltas are positive, you are creating more objects in memory. I'd would then take another snapshot after a given period of time, say 5 minutes. Then compare the results again. Looking at delta

If your deltas are constant, you are doing an good job at memory manageemnt. If negative, your code is clean and your used objects are able to be properly collected, again a great job.

If your deltas keep increasing, you probably have a memory leak.

Also,

document.getElementsByTagName('*'); // a count of all DOM elements

would be useful to see if you are steadily increasing you DOM elements.




回答2:


Chrome also has the "about:memory" page, but I agree with IAbstractDownVoteFactory - developer tools are the way to go!



来源:https://stackoverflow.com/questions/7473307/how-to-measure-memory-usage-and-efficiency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!