How to use ImageBitmapLoader's .close() method

Looking at the ImageBitmap example, you have to call imagebitmap.close() to free the memory, as stated in this comment block:

ImageBitmap should be disposed of when done with it. Can't be done until it's actually uploaded to WebGLTexture.

How does my application know when the ImageBitmap is ready to be disposed? Am I stuck using something like using a setTimeout?

    let loader = new THREE.ImageBitmapLoader()
    loader.setOptions( { imageOrientation: 'flipY' } );
    loader.load( srcs[i] , function ( imageBitmap ) {
        const texture = new THREE.CanvasTexture( imageBitmap );
        texture.colorSpace = THREE.SRGBColorSpace;
        texture.minFilter = THREE.LinearFilter
        texture.generateMipmaps  = false
        let mat  = new THREE.MeshBasicMaterial()
        let mesh = new THREE.Mesh(g,mat)
        mesh.position.copy(e.position.clone()) = texture
        /* ImageBitmap should be disposed when done with it
        Can't be done until it's actually uploaded to WebGLTexture */
        // imageBitmap.close();
        setTimeout(() => imageBitmap.close(), 1 ) //ugly
    }, function ( p ) {
        console.log( p );
    }, function ( e ) {
        console.log( e );
    } );

Try this:

texture.onUpdate = function() {



onUpdate() is executed whenever a texture upload to the GPU has finished.

Using setTimeout() is indeed ugly since you might close the image bitmap before the texture upload happens.

1 Like

worked perfectly. thanks!