nispok/snackbar

Snackbar leaks activity

Closed this issue · 6 comments

Version 2.10.+ (2.10.8)
Snackbar leaks activity if activity is closed while snackbar is visible.

GC ROOT static com.nispok.snackbar.SnackbarManager.currentSnackbar
* references com.nispok.snackbar.Snackbar.mTargetActivity
* leaks com.example.MainActivity instance

Snackbar is displayed in activity:
SnackbarManager.show(Snackbar.with(this).type(SnackbarType.MULTI_LINE).text("text"));
//dismissing onPause doesn't solve issue
onPause(){
SnackbarManager.dismiss();
}

I get this as well when using SnackbarManager, so I reverted back to the normal Snackbar class which does not leak the activity.

My leak trace seems a little more specific:

* GC ROOT static com.nispok.snackbar.SnackbarManager.currentSnackbar
* references com.nispok.snackbar.Snackbar.snackbarText
* references android.support.v7.widget.AppCompatTextView.mContext
* leaks ...activities.NowActivity instance

I see similar as well:

05-20 11:49:24.893 25902-26313/com.gmspartnersltd.earthmiles.debug D/LeakCanary﹕ In com.gmspartnersltd.earthmiles.debug:1.6:6.
* com.gmspartnersltd.earthmiles.views.MainActivity has leaked:
* GC ROOT static com.nispok.snackbar.SnackbarManager.currentSnackbar
* references com.nispok.snackbar.Snackbar.mContext
* leaks com.gmspartnersltd.earthmiles.views.MainActivity instance
* Reference Key: 3f9851c5-7028-4f47-90ff-045ed815b178
* Device: Genymotion generic Google Nexus 5 - 5.0.0 - API 21 - 1080x1920 vbox86p
* Android Version: 5.0 API: 21
* Durations: watch=5008ms, gc=116ms, heap dump=772ms, analysis=5015ms

wmora commented

SnackbarManager should handle the context as a weak reference :-/

Noticied the memory leak too when using SnackManager