Skip to content

Commit

Permalink
Delete GL textures when they are released from the texture registry. (f…
Browse files Browse the repository at this point in the history
…lutter#7836)

On Android we were never deleting the textures allocated for
the texture registry, which resulted in a memory leak, see:
flutter/flutter#24145
  • Loading branch information
amirh authored Feb 15, 2019
1 parent 69e4606 commit 10cee61
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion shell/platform/android/android_external_texture_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ AndroidExternalTextureGL::AndroidExternalTextureGL(
const fml::jni::JavaObjectWeakGlobalRef& surfaceTexture)
: Texture(id), surface_texture_(surfaceTexture), transform(SkMatrix::I()) {}

AndroidExternalTextureGL::~AndroidExternalTextureGL() = default;
AndroidExternalTextureGL::~AndroidExternalTextureGL() {
if (state_ == AttachmentState::attached) {
glDeleteTextures(1, &texture_name_);
}
}

void AndroidExternalTextureGL::OnGrContextCreated() {
state_ = AttachmentState::uninitialized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public void release() {
if (released) {
return;
}
unregisterTexture(id);
surfaceTexture.release();
unregisterTexture(id);
released = true;
}
}
Expand Down
7 changes: 6 additions & 1 deletion shell/platform/android/io/flutter/view/FlutterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1128,11 +1128,16 @@ public void release() {
return;
}
released = true;
mNativeView.getFlutterJNI().unregisterTexture(id);

// The ordering of the next 3 calls is important:
// First we remove the frame listener, then we release the SurfaceTexture, and only after we unregister
// the texture which actually deletes the GL texture.

// Otherwise onFrameAvailableListener might be called after mNativeView==null
// (https://github.com/flutter/flutter/issues/20951). See also the check in onFrameAvailable.
surfaceTexture.setOnFrameAvailableListener(null);
surfaceTexture.release();
mNativeView.getFlutterJNI().unregisterTexture(id);
}
}
}

0 comments on commit 10cee61

Please sign in to comment.