title: Freeing memory of ThreeJS application
body: <p>I am currently having issues with freeing memory in my ThreeJS application.</p>
  
  <p><strong>I am aware there are already several questions about this problem:</strong></p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/21851349/freeing-memory-in-three-js">freeing memory in three.js</a></li>
  <li><a href="https://stackoverflow.com/questions/39904976/freeing-memory-with-threejs">Freeing memory with threejs</a></li>
  <li><a href="https://stackoverflow.com/questions/33152132/three-js-collada-whats-the-proper-way-to-dispose-and-release-memory-garbag">Three.js Collada - What&#39;s the proper way to dispose() and release memory (garbage collection)?</a></li>
  </ul>
  
  <p>I <strong>do</strong> dispose my objects using the following Typescript function I've made :</p>
  
  <pre><code>function dispose( object3D: THREE.Object3D ): void
  {
      // Dispose children first
      for ( let childIndex = 0; childIndex &lt; object3D.children.length; ++childIndex )
      {
          this.dispose( object3D.children[childIndex] );
      }
  
      object3D.children = [];
  
      if ( object3D instanceof THREE.Mesh )
      {
          // Geometry
          object3D.geometry.dispose();
  
          // Material(s)
          if ( object3D.material instanceof THREE.MultiMaterial )
          {
              for ( let matIndex = 0; matIndex &lt; object3D.material.materials.length; ++matIndex )
              {
                  object3D.material.materials[matIndex].dispose();
                  object3D.material.materials[matIndex] = null;
              }
              object3D.material.materials = [];
          }
  
          if ( object3D.material.dispose )
          {
              object3D.material.dispose();
              object3D.material = null;
          }
      }
  
      // Remove from parent
      if ( object3D.parent )
          object3D.parent.remove( object3D );
  
      object3D = null;
  }
  </code></pre>
  
  <p>However, when I do heap snapshots using Chrome Dev Tools, I still have tons and tons of :</p>
  
  <ul>
  <li>Arrays</li>
  <li>Vector2 (uvs in <code>__directGeometry</code> , ... )</li>
  <li>Vector3 (vertices in <code>geometry</code>, normal in <code>faces</code>, vertexColors in <code>faces</code>, ...)</li>
  <li>Face3 (faces in <code>geometry</code>)</li>
  <li>Color (colors in <code>__directGeometry</code>, ...)</li>
  <li>JSArrayBufferData (color, normal, in <code>attributes</code> of <code>geometry</code>, ...)</li>
  </ul>
  
  <p>Because of all the data in memory, my application gets killed by Jetsam on iOS, see : <a href="https://stackoverflow.com/questions/44258746/jetsam-kills-webgl-application-on-ios">Jetsam kills WebGL application on iOS</a></p>
  
  <p>I suspect some data inside the library is not freed up when I ask it to.</p>