GrenderG/Toasty

Memory leak when allowQueue=false

Open

#128 geöffnet am 12. Nov. 2019

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Java (822 Forks)batch import
bughelp wanted

Repository-Metriken

Stars
 (6.535 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

If allowQueue parameter set to false Toasty uses lastToast static variable to save previous Toast object which holds reference to Context causing memory leak. Leak is reported by com.squareup.leakcanary library.

You need to set allowQueue to true to eliminate leak (no static reference to Context).

// Causing leak
            Toasty.custom(_context, _text,
                    ContextCompat.getDrawable(_context, R.drawable.ic_alert_white_36dp),
                    ContextCompat.getColor(_context, R.color.warn_background),
                    ContextCompat.getColor(_context, R.color.defaultTextColor),
                    _duration, true, true).show();

// No leak
Toasty.Config.getInstance().allowQueue(true).apply();
Toasty.custom(_context, _text,
                    ContextCompat.getDrawable(_context, R.drawable.ic_alert_white_36dp),
                    ContextCompat.getColor(_context, R.color.warn_background),
                    ContextCompat.getColor(_context, R.color.defaultTextColor),
                    _duration, true, true).show();

Contributor Guide