# Best strategy for disposing invisible textures loaded by GLTFLoader

**URL:** <https://discourse.threejs.org/t/best-strategy-for-disposing-invisible-textures-loaded-by-gltfloader/5627>\
**Category:** Questions\
**Tags:** gltf-loader, textures\
**Created:** [January 7, 2019, 9:53am UTC](https://discourse.threejs.org/t/best-strategy-for-disposing-invisible-textures-loaded-by-gltfloader/5627 "2019-01-07T09:53:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpadovani](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rpadovani/32/3747_2.png) [@rpadovani](https://discourse.threejs.org/u/rpadovani)\
**Post date:** [January 7, 2019, 9:53am UTC](https://discourse.threejs.org/t/best-strategy-for-disposing-invisible-textures-loaded-by-gltfloader/5627/1 "2019-01-07T09:53:52Z")

</div>

Hello everyone!

I have a GLTF file with a lot of textures distributed on a large scene: while the user explores the scene, the memory load goes up because new textures are loaded in memory, but old ones aren’t disposed of.

I’d like to call `.dispose()` on textures that are not visible on the scene, but I don’t have a direct reference to them, since they are managed by the GLTFloader. How can I dispose them, without having to use a custom loader?

Thanks!

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [January 7, 2019, 11:05am UTC](https://discourse.threejs.org/t/best-strategy-for-disposing-invisible-textures-loaded-by-gltfloader/5627/2 "2019-01-07T11:05:37Z")

</div>

Disposal of textures only works if you call `.dispose()` on a texture object. Have you tried to traverse through the `glTF` scene that is returned by the loader? Something like:

```auto
loader.load( 'model.gltf', function ( gltf ) {

    gltf.scene.traverse( function ( child ) {

        if ( child.material ) {

            // do something with child.material
						
       }

    } );

    scene.add( gltf.scene );

}

```

In this way you can create a map/set of all textures in the scene and dispose them if necessary.

---

<div class="post-metadata">

**Author:** ![doum](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/doum/32/5825_2.png) [@doum](https://discourse.threejs.org/u/doum)\
**Post date:** [January 7, 2019, 11:33am UTC](https://discourse.threejs.org/t/best-strategy-for-disposing-invisible-textures-loaded-by-gltfloader/5627/3 "2019-01-07T11:33:53Z")

</div>

You set material opacity = 0

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [January 7, 2019, 11:52am UTC](https://discourse.threejs.org/t/best-strategy-for-disposing-invisible-textures-loaded-by-gltfloader/5627/4 "2019-01-07T11:52:48Z")

</div>

That does not dispose a texture…

---

<div class="post-metadata">

**Author:** ![rpadovani](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rpadovani/32/3747_2.png) [@rpadovani](https://discourse.threejs.org/u/rpadovani)\
**Post date:** [January 7, 2019, 12:05pm UTC](https://discourse.threejs.org/t/best-strategy-for-disposing-invisible-textures-loaded-by-gltfloader/5627/5 "2019-01-07T12:05:15Z")

</div>

Thanks! I already keep track of the children, I haven’t tough about using `child.material.map.dispose()`, that was easy, I just needed to add some logic for checking visibility of the texture 🙂

Thank you very much!
