android-crop icon indicating copy to clipboard operation
android-crop copied to clipboard

1.0.0 Memory drain crop activity Samsung Galaxy S3, Android 4.3

Open tschiemer opened this issue 10 years ago • 6 comments

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.

screen shot 2015-07-22 at 12 19 15

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..

tschiemer avatar Jul 22 '15 17:07 tschiemer

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

  1. in CropImageActivity.calculateBitmapSampleSize, changed maxSize to what you think good, in my case, I limited it to x2 of screenWidth
  2. 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

tsengvn avatar Jul 23 '15 16:07 tsengvn

I have similar problem!

MrVilkaman avatar Jul 31 '15 10:07 MrVilkaman

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?

jdamcd avatar Sep 07 '15 09:09 jdamcd

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.

jdamcd avatar Sep 07 '15 09:09 jdamcd

I have the same issue. The problem occurred on Samsung Galaxy S3 with Android 4.4.4.

Sunghoon-Jung avatar Oct 10 '15 12:10 Sunghoon-Jung

@tsengvn how to do resize the rect with sampleSize ??

taco2548 avatar Jul 27 '18 12:07 taco2548