Detect available memory inside of a WebView : <p>I'm building an app that contains a <code>WebView</code> that runs some JavaScript code. That JavaScript code is quite allocation heavy and can require a lot of memory.</p>

<p>Sometimes, the amount of required memory exceeds the amount JavaScript can require and crashes the Chromium process of the WebView which crashes my app.</p>

<p>I listen to <code>onMemoryTrim</code> in my application - but it is never called in this scenario on devices with more than 1GB of memory. (Not even with <code>TRIM_MEMORY_RUNNING_LOW</code>).</p>

<p>Is there any way I could detect my WebView is running low on memory and either kill it or let it know (so it can free memory)? </p>

<p>I've tried polling <code>performance.memory</code> but it did not work. The following script crashes the WebView if executed in it:</p>

<pre><code>var a = [];

var kek = () =&gt; {
  var b = [];
  for(var i = 0; i &lt; 1024 * 1024 * 2; i++) b.push(Math.random());
  return b;
}

var ival = setInterval(() =&gt; {
  let m = performance.memory;
  if(m.jsHeapSizeLimit - m.usedJSHeapSize &lt; 1e5) {
    console.log("Memory limited")
  } else {
    a.push(kek());
  }
});
</code></pre>

<p>Is there any way to detect memory is about to run out so I can handle it gracefully without the app crashing? </p>
