Skip to content

Commit

Permalink
fix: Recycling of screenshot bitmaps (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Jan 30, 2024
1 parent 7fb8655 commit 2859d56
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ public static String takeScreenshot(@Nullable final Rect cropArea) throws TakeSc
return takeDeviceScreenshot(String.class);
}

Bitmap screenshot = takeDeviceScreenshot(Bitmap.class);
Bitmap fullScreenshot = takeDeviceScreenshot(Bitmap.class);
Bitmap elementScreenshot = null;
try {
final Bitmap elementScreenshot = crop(screenshot, cropArea);
screenshot.recycle();
screenshot = elementScreenshot;
return Base64.encodeToString(compress(screenshot), Base64.NO_WRAP);
elementScreenshot = crop(fullScreenshot, cropArea);
return Base64.encodeToString(compress(elementScreenshot), Base64.NO_WRAP);
} finally {
screenshot.recycle();
fullScreenshot.recycle();
if (elementScreenshot != null && elementScreenshot != fullScreenshot) {
elementScreenshot.recycle();
}
}
}

Expand Down

0 comments on commit 2859d56

Please sign in to comment.