Skip to content

Commit 7a25945

Browse files
authored
Fix memory leak when loading texture with ImageBitmap (#499)
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
1 parent 0df8db3 commit 7a25945

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/three/TilesRenderer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,13 @@ export class TilesRenderer extends TilesRendererBase {
765765
for ( let i = 0, l = textures.length; i < l; i ++ ) {
766766

767767
const texture = textures[ i ];
768+
769+
if ( texture.image instanceof ImageBitmap ) {
770+
771+
texture.image.close();
772+
773+
}
774+
768775
texture.dispose();
769776

770777
}

0 commit comments

Comments
 (0)