An issue from community.
thruthesky opened this issue · 0 comments
thruthesky commented
I'm using the audio wave library. Very nice. Thanks.
Here is what I found. When I pop the view the time is still running which is causing setState to be called. The debugger is indicating that a memory leak is likely occurring.
The fix that I did was to add a local bool variable cancelTimer; a dispose() function. In the dispose function I set the cancelTimer = true. In the setState I check the cancelTimer and cancel the timer if needed.
This cleared up the issue.
bool cancelTimer = false;
@OverRide
void dispose() {
cancelTimer = true;
super.dispose();
print('Audio wave Dispose called.');
}
if (mounted) {
setState(() {
if(cancelTimer) {
timer.cancel();
}
});
}