Crouton icon indicating copy to clipboard operation
Crouton copied to clipboard

memory leak in DefaultAnimationsBuilder.java

Open soxunyi opened this issue 9 years ago • 5 comments

final class DefaultAnimationsBuilder { private static final long DURATION = 400L; private static Animation slideInDownAnimation; // memory leak, hold on activity private static Animation slideOutUpAnimation; // memory leak, hold on activity ... }

If you use leakcanary (https://github.com/square/leakcanary), you can detect this memory leak.

Please check it. Thanks.

soxunyi avatar Jul 12 '15 11:07 soxunyi

Same here, I also detected this, with Leakcanar, this is a showstopper for me.

laszlo-galosi avatar Aug 24 '15 09:08 laszlo-galosi

Pull requests are gladly accepted. Also, see the deprecation notice section of the README for alternatives.

keyboardsurfer avatar Aug 24 '15 10:08 keyboardsurfer

Crouton itself holds an Activity, but I think it's unnecessary.

  1. Some of the constructors do need an Activity to use findViewById
  2. The only non-static method that uses the acitivity is in measureCroutonView
widthSpec = MeasureSpec.makeMeasureSpec(this.activity.getWindow().getDecorView().getMeasuredWidth(), -2147483648);

I'd say there are several ways to get the width without the need of an activity. See http://stackoverflow.com/a/1016941/218473

  1. The rest of uses of activity could be replaced by any context, which could be the application context. This change could be made without modifying Crouton's public API.

Anyway, this library is deprecated and I fear I might miss something (I just did a quick research), so I'd suggest changing to support SnackBar.

Maragues avatar Aug 31 '15 14:08 Maragues

There is a work around. If you set a Configuration object on the Crouton then the default animations don't get used and the activity doesn't get attached to them.

Configuration configuration = new Configuration.Builder()
    .setInAnimation(R.anim.abc_slide_in_top)
    .setOutAnimation(R.anim.abc_slide_out_top)
    .build();

Crouton crouton = Crouton.make(...);
crouton.setConfiguration(configuration);
// Show it

jferlisi avatar Sep 28 '15 15:09 jferlisi

I can confirm that #241 fixes the issue.

Sloy avatar Aug 25 '16 07:08 Sloy