Crouton
Crouton copied to clipboard
memory leak in DefaultAnimationsBuilder.java
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.
Same here, I also detected this, with Leakcanar, this is a showstopper for me.
Pull requests are gladly accepted. Also, see the deprecation notice section of the README for alternatives.
Crouton itself holds an Activity, but I think it's unnecessary.
- Some of the constructors do need an Activity to use findViewById
- 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
- 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.
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
I can confirm that #241 fixes the issue.