Skip to content

Consider ensuring that the method unregisterTexture is called even if customers forget to call SurfaceTextureEntry.release #88571

@ColdPaleLight

Description

@ColdPaleLight

At present, if customers forget to call SurfaceTextureEntry.release, the Texture stored in TextureRegistry will not have a chance to be unregistered. Because TextureRegistry::UnregisterTexture is not called https://github.com/flutter/engine/blob/master/common/graphics/texture.cc#L22

I think it’s easy for customers to make such mistakes sometimes, for example in the following scenario

TextureRegistry.SurfaceTextureEntry currentTexture = textureRegistry.createSurfaceTexture();

//do something else
...... 

// Oops, the customer forgot to release the previous one when generating a new SurfaceTextureEntry
currentTexture = textureRegistry.createSurfaceTexture();

In fact, we have a chance to know whether customers have called SurfaceTextureEntry.release. We can even call unregisterTexture when they forget to call release.
We can add the finalize method to SurfaceTextureRegistryEntry, such as this:

  @Override
  protected void finalize() throws Throwable {
      try {
          if (released) {
              return;
          }
          
          handler.post(new Runnable() {
              public void run() {
                  if (released) {
                      return;
                  }
                  Log.v(TAG, "Releasing a SurfaceTexture (" + id + ").");
                  unregisterTexture(id);
                  released = true;
              }
          });
      } finally {
          super.finalize();
      }
  }

I think some customers encountered the issue #83090 because they forgot to call SurfaceTextureEntry.release. I also found this problem when reviewing other people's code.

Proposal

Ensuring that the method unregisterTexture is called even if customers forget to call SurfaceTextureEntry.release

If this issue is reasonable, I can file a PR with tests

/cc @jason-simmons

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Fluttercustomer: alibabaengineflutter/engine related. See also e: labels.r: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions