Skip to content

Memory leak: Texture dispose() method doesn't close ImageBitmap #23953

@deenns

Description

@deenns

Describe the bug

Currently, textures from glb files are loaded as ImageBitmap objects, which are not garbage collected by default - one needs to call the close() method

However, the Texture.prototype.dispose() method doesn't do it.

To Reproduce

  1. Open https://gltf-viewer.donmccurdy.com/ in Chrome
  2. Open the browser task manager (Shift+Esc or Menu -> More Tools -> Task Manager)
  3. Find the tab in the task manager and see its memory consumption. It will be about 20-30MB.
  4. Download this glb model with big 4K textures
  5. Drag and drop the model on the viewer several times. You will see that the memory consumption rapidly increases, despite the fact all textures are disposed of each time

Expected behavior

The code texture.source.data.close?.() before texture.dispose() solves the problem.
But I would expect the Texture.prototype.dispose() method to do it automatically, especially given the fact, the textures are created by the gltf loader, and their type isn't obvious. Alternatively, a bool flag deep=true can be passed to the method to dispose of the inner resource.

If it's by design, it should be clearly written in the documentation.

Platform:

  • Browser: Chrome
  • Three.js version: r139

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions