GrenderG / GrenderG/Toasty

Memory leak when allowQueue=false

Open
#128 3 comments 0 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
Java
Stars
6.6k
Forks
803
PR merge metrics
No merged PRs in 30d

Description

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

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.