简体   繁体   中英

How to measure memory usage and efficiency?

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?

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.

Chrome也有“about:memory”页面,但我同意IAbstractDownVoteFactory - 开发者工具是要走的路!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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