Skip to content

Conversation

@kreativityapps
Copy link
Contributor

On Android tmpBitmap consumes unnecessary memory in rotate and flip and there is no need for it.

This change halves the memory consumption avoiding oom issues.

@AlexV525
Copy link
Member

Thanks for the improvement. Do you have any statistic data to share before and after this change?

@kreativityapps
Copy link
Contributor Author

Before the fix I had a bunch of crashes with this:

java.lang.OutOfMemoryError: 
  at android.graphics.Bitmap.nativeCreate (Native Method)
  at android.graphics.Bitmap.createBitmap (Bitmap.java:1122)
  at android.graphics.Bitmap.createBitmap (Bitmap.java:952)
  at top.kikt.flutter_image_editor.core.ImageHandler.handleRotate (ImageHandler.java:29)
  at top.kikt.flutter_image_editor.core.ImageHandler.handle (ImageHandler.java:73)
  at top.kikt.flutter_image_editor.FlutterImageEditorPlugin.handle (FlutterImageEditorPlugin.java:17)
  at top.kikt.flutter_image_editor.FlutterImageEditorPlugin.access$handle (FlutterImageEditorPlugin.java)
  at top.kikt.flutter_image_editor.FlutterImageEditorPlugin$onMethodCall$$inlined$runOnBackground$1.run (FlutterImageEditorPlugin.java:55)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
  at java.lang.Thread.run (Thread.java:919)

The fix solved it, I will try to gather some memory measurements before-after when I have the time.

@kreativityapps
Copy link
Contributor Author

I rotated several times the same image of size 4.5MB in my app.

Before:

  • memory consumption goes up each time the image is rotated, above 400MB

Screen Shot 2021-10-20 at 1 31 11 PM

Screen Shot 2021-10-20 at 1 30 49 PM

After:

  • memory consumption comes back after rotation, steady around 220MB

Screen Shot 2021-10-20 at 1 08 20 PM

Screen Shot 2021-10-20 at 1 07 46 PM

Thanks for this great package!

Copy link
Member

@AlexV525 AlexV525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This look very promising! Thanks for the huge improvement.
LGTM

@AlexV525 AlexV525 merged commit e74ffb4 into fluttercandies:master Oct 21, 2021
@AlexV525
Copy link
Member

Nit picking after merged: we recommend the minimum commit policy, which means this improvement should only including the native part as it scoped. But it's okay for now, can be improved in other PRs or projects.

@AlexV525
Copy link
Member

AlexV525 commented Nov 2, 2021

Oops, sorry about forgetting to publish this. Will rush to it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants