javascript来查找可用的内存 [英] javascript to find memory available

查看:127
本文介绍了javascript来查找可用的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们立即明白:这不是一个关于内存泄漏的问题!
我有一个页面,允许用户输入一些数据和一个JavaScript来处理这些数据并产生一个结果。
JavaScript在DIV上生成增量输出,如下所示:

Let's make it immediately clear: this is not a question about memory leak! I have a page which allows the user to enter some data and a JavaScript to handle this data and produce a result. The JavaScript produces incremental outputs on a DIV, something like this:

(function()
{
   var newdiv = document.createElement("div");
   newdiv.innerHTML = produceAnswer();
   result.appendChild(newdiv);
   if (done) {
      return;
   } else {
      setTimeout(arguments.callee, 0);
   }
})();

在某些情况下,计算将产生这么多的数据,IE8将失败
与此消息:

Under certain circumstances the computation will produce so much data that IE8 will fail with this message:


处理太多数据时存储空间不足

not enough storage when dealing with too much data

问题是:
是我可以计算出多少数据是太多的数据?

The question is: is there way I can work out how much data is too much data?

因为我说没有bug解决。这是一个真正的内存不足,因为计算
需要创建太多的html元素。

as I said there is no bug to solve. It's a genuine out of memory because the computation requires to create too many html elements.

我的想法是在执行计算之前运行一个函数如果浏览器会成功,请提前。但为了这样做,以一个通用的方式,我想我需要找到我的浏览器可用的内存。

My idea would be to run a function before executing the computation to work out ahead if the browser will succeed. But to do so, in a generic way, I think I need to find the memory available to my browser.

欢迎任何建议。

推荐答案

JavaScript(在浏览器中)在沙盒中运行,这意味着它在访问可能导致安全问题的本地文件,系统资源等,所以不能检测内存使用情况。

Javascript (in the browser) is run in a sandbox, which means that it is fenced-off from accessing things that could cause security issues such as local files, system resources etc - so no, you can't detect memory usage.

其他答案状态,你可以通过暂停之间的实现或使用较少的资源密集型代码,但每个浏览器都有其限制。

As the other answers state, you can make the task easier for the browser by pausing between implementations or using less resource-intensive code, but every browser has its limits.

这篇关于javascript来查找可用的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆