android-crop
android-crop copied to clipboard
1.0.0 Memory drain crop activity Samsung Galaxy S3, Android 4.3
Hi..
For some reason there is quite the memory drain by the crop activity version 1.0.0 at startup time often leading to exhausting the memory either directly at start of the activity or when trying to crop larger sectors (but smaller work out alright). Also see image.

Edit: Ah yes, if I could cancel the crop action the used memory would not be freed whereas it would when actually cropped, but that's maybe rather a GC question ( not investigated thoroughly, sorry)
This kept occurring on a specific device (Samsung Galaxy S3, Android 4.3) after reboots etc, but not on other tested devices (Nexus 4, 5.1.1; Samsung Galaxy Tab2, 4.1.2).
Also quite noticable was the interaction lag where the crop-selection would keep lagging behind a bit.
Also I used the crop-activity of the based-upon project https://github.com/lvillani/android-cropimage whose memory usage was barely noticable and it was charmingly fluid.
Following you'll find the equivalent code using the two libraries:
Uri in,out;
int width,height;
// set the values..
// android-cropimage 1.1.0
CropImageIntentBuilder builder = new CropImageIntentBuilder(1,1,width,height, out);
builder.setSourceImage(in);
builder.setOutlineColor(getResources().getColor(R.color.HoloLightBlue));
startActivityForResult(builder.getIntent(getActivity()), RESULT_IMAGE_CROP);
// android-crop 1.0.0
Crop.of(in,out)
.withAspect(1,1)
.withMaxSize(width,height)
.start(getActivity(), this, RESULT_IMAGE_CROP);
// note: called method is:
// public void start(Context context, android.support.v4.app.Fragment fragment, int requestCode)
possibly relevant libraries
com.android.support:appcompat-v7:22.2.0
com.android.support:support-v13:21.0.3
I quite like the library (thanks for providing it!) but momentarily I'll have to stick to android-cropimage..
I also faced this issue on multiple devices. But I love this library, so I decided to dig into code and here is some of my changes that reduce OOM alot
- in CropImageActivity.calculateBitmapSampleSize, changed maxSize to what you think good, in my case, I limited it to x2 of screenWidth
- in CropImageActivity.decodeRegionCrop, resize the rect with sampleSize, also put sampleSize into BitmapFactory.Options of decoder.decodeRegion, remove postScale below in matrix, also recycle decoder after method done.
I plan to push commit into repo, but I need to test with more devices to make sure my changes are right
I have similar problem!
Thanks for the detailed report!
cancel the crop action the used memory would not be freed whereas it would when actually cropped
Sounds like a leak. Did you see this on all devices tested or just the Samsung?
CropImageActivity.decodeRegionCrop, resize the rect with sampleSize, also put sampleSize into BitmapFactory.Options of decoder.decodeRegion, remove postScale below in matrix, also recycle decoder after method done
I'd definitely be interested in a PR with those changes @tsengvn, at least to do some comparative profiling.
I have the same issue. The problem occurred on Samsung Galaxy S3 with Android 4.4.4.
@tsengvn how to do resize the rect with sampleSize ??