title: How do you detect memory limits in JavaScript?
body: <p>Can browsers enforce any sort of limit on the amount of data that can be stored in JavaScript objects? If so, is there any way to detect that limit?</p>
  
  <p>It appears that by default, Firefox does not:</p>
  
  <pre><code>var data;
  $("document").ready(function() {
    data = [];
    for(var i = 0; i &lt; 100000000000; i++) {
      data.push(Math.random());
    }
  });
  </code></pre>
  
  <p>That continues to consume more and more memory until my system runs out.</p>
  
  <p>Since we <a href="https://stackoverflow.com/a/2027797/1454117">can't detect available memory</a>, is there any other way to tell we are getting close to that limit?</p>
  
  <p><strong>Update</strong></p>
  
  <p>The application I'm developing relies on very fast response times to be usable (it's the core selling point). Unfortunately, it also has a very large data set (more than will fit into memory on weaker client machines). Performance can be greatly improved by preemptively loading data strategically (guessing what will be clicked). The fallback to loading the data from the server works when the guesses are incorrect, but the server round trip isn't ideal. Making use of every bit of memory I can makes the application as performant as possible.</p>
  
  <p>Right now, it works to allow the user to "configure" their performance settings (max data settings), but users don't want to manage that. Also, since it's a web application, I have to handle users setting that per computer (since a powerful desktop has a lot more memory than an old iPhone). It's better if it just uses optimal settings for what is available on the systems. But guessing too high can cause problems on the client computer too.</p>