-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
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