Skip to content

Commit

Permalink
Remove the unused FlutterImageView from FlutterView to avoid leaks (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
0xZOne authored Jan 20, 2022
1 parent d3da092 commit 1fbf5ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,10 @@ public void detachFromFlutterEngine() {

if (flutterImageView != null) {
flutterImageView.closeImageReader();
// Remove the FlutterImageView that was previously added by {@code convertToImageView} to
// avoid leaks when this FlutterView is reused later in the scenario where multiple
// FlutterActivitiy/FlutterFragment share one engine.
removeView(flutterImageView);
flutterImageView = null;
}
previousRenderSurface = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,24 @@ public void detachFromFlutterEngine_revertImageView() {
assertFalse(flutterView.renderSurface instanceof FlutterImageView);
}

@Test
public void detachFromFlutterEngine_removeImageView() {
FlutterView flutterView = new FlutterView(RuntimeEnvironment.application);
FlutterEngine flutterEngine =
spy(new FlutterEngine(RuntimeEnvironment.application, mockFlutterLoader, mockFlutterJni));

flutterView.attachToFlutterEngine(flutterEngine);
flutterView.convertToImageView();
assertEquals(flutterView.getChildCount(), 2);
View view = flutterView.getChildAt(1);
assertTrue(view instanceof FlutterImageView);

flutterView.detachFromFlutterEngine();
assertEquals(flutterView.getChildCount(), 1);
view = flutterView.getChildAt(0);
assertFalse(view instanceof FlutterImageView);
}

@Test
public void detachFromFlutterEngine_closesImageView() {
FlutterEngine flutterEngine =
Expand Down

0 comments on commit 1fbf5ef

Please sign in to comment.