GrenderG/Toasty

Memory leak when allowQueue=false

Open

#128 建立於 2019年11月12日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)Java (822 fork)batch import
bughelp wanted

倉庫指標

Star
 (6,535 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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();

貢獻者指南