Skip to content

Commit

Permalink
Fix memory leak when loading texture with ImageBitmap (#499)
Browse files Browse the repository at this point in the history
During rendering large-scale 3DTiles with high resolution textures, we identified a memory leak problem. When continuously loading new tiles, memory usage would constantly increase without being released. And the browser will crash after console reported the error `Couldn't load texture blob: http://xxx`

I found that it cause by GLTFLoader loaded textures with ImageBitmap and did not close or dispose it when tiles be disposed. https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/GLTFLoader.js#L2547

After this fix, I have tested that the memory won't increase endlessly. It will reach the top when geometry and textures in scene maintain in a reasonable value.

related issue: mrdoob/three.js#23953
  • Loading branch information
Junior2Ran committed Mar 8, 2024
1 parent 0df8db3 commit 7a25945
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/three/TilesRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,13 @@ export class TilesRenderer extends TilesRendererBase {
for ( let i = 0, l = textures.length; i < l; i ++ ) {

const texture = textures[ i ];

if ( texture.image instanceof ImageBitmap ) {

texture.image.close();

}

texture.dispose();

}
Expand Down

0 comments on commit 7a25945

Please sign in to comment.