title: What is released when restarting an iOS device?
body: <p><strong>SHORT QUESTION</strong></p>
  
  <p>I have a bug that only disappears when I restart my device. I would like to know what is released when restarting an iOS device in order to have an idea about what my bug is.
  Releasing my cache and my RAM don't help to fix my bug, so I wonder <em>what else</em> could be released that fix my bug for a short time.</p>
  
  <p><strong>CONTEXT</strong></p>
  
  <p>I have a web app using WebGL and BabylonJS. It works really fine on all devices and all browsers except on iOS. With Safari, I always end by having the error message "A problem occurred with this web page so it was reloaded".</p>
  
  <p>It happened on an iPad Air 2 (2Go RAM) running iOS 10.3.3 but I saw the same bug on every iOS device I could have in my hands. That's why I consider it as iOS only related.
  I'm aware about iOS resource limits : <a href="https://stackoverflow.com/a/22193143/5053300">https://stackoverflow.com/a/22193143/5053300</a></p>
  
  <p>I tried to debug this for months, the bug appears randomly, sometimes quickly, sometimes slowly. There's nothing consistent so it's totally impossible to debug.</p>
  
  <p>The best guess is that it's a memory issue because crashs seem to appear faster each time. And because the error message is quite always linked to memory issues.</p>
  
  <p>I suspect textures and renderTargetTextures to take more and more memory (but I don't understand why it wouldn't be released, I don't keep useless references).</p>
  
  <p>But there's something I'm sure : when I restart my device, it always work the first time (until I reload once, then begins the downward spiral).</p>
  
  <p>If I clean my cache (via settings -> Safari) and my RAM (pressing home button when we are in shut down screen), the bug is still here. But if I restart my device, it disappears.
  Something in memory is released and I would like to know what.</p>
  
  <p>But I also could be totally wrong and it could be something else than memory, I'm open to all your suggestions.</p>
  
  <p>Thanks in advance, it drives me crazy for months !</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This is what JS Heap looks like :</p>
  
  <p><img src="https://i.stack.imgur.com/qmSvU.png" alt="JS Heap"></p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>A <a href="https://www.babylonjs-playground.com/#H4PMHG#15" rel="nofollow noreferrer">scene asking for 90 renderTargetTextures</a> (379x890) each frame does work on iOS.
  My app does work if I don't ask for any renderTargetTextures. But it crashes more or less quickly if I only ask for one small renderTargetTexture each frame.
  What conclusions can I get from this observation ? Does it corroborate or deny the idea of a memory issue ?</p>
  
  <p><strong>UPDATE 3</strong></p>
  
  <p>There's no clue the following code really is the cause of the issue, but commenting/uncommenting it generaly makes disappear/appear the bug.</p>
  
  <pre><code>var texture = generateTexture();
  function generateTexture() {
      var rt1 = new BABYLON.RenderTargetTexture("rt1", { width: scene.getEngine().getRenderWidth(), height: scene.getEngine().getRenderHeight() }, scene, false, true, scene.getEngine().TEXTURETYPE_UNSIGNED_BYTE, false);
      rt1.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
      rt1.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
      rt1.renderList.push(sphere);
      rt1.onBeforeRender = function() {
          sphere.material = std1;
      };
      scene.customRenderTargets.push(rt1);
      return rt1;
  }
  </code></pre>
  
  <p>I may insist on the fact that this code works in the <a href="https://www.babylonjs-playground.com/#H4PMHG#15" rel="nofollow noreferrer">link posted in update 2</a> so I don't think this code is relevant. The only thing is, commenting this part of the app seems to remove the random bug.
  This code asks the 3D engine to render into one intermediary texture before to render to the screen. So this code impacts each frame.
  In the link, I ask the engine to render into textures 90 times before to render to the screen.</p>
  
  <p><strong>UPDATE 4: PROBLEM SOLVED</strong></p>
  
  <p>The issue didn't depend on what is released on iOS restart, so I can't answer to my own question. But I can say that iOS doesn't like dynamic lighting.
  From now on, all our projects will be limited to one light on iOS devices.</p>
  
  <p>More lights, more computations each frame. It's too much for iOS that kills apps that ask for too much memory in a short time.</p>