且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

防止Android中的内存泄漏

更新时间:2021-09-27 23:16:06

我已经设法解决了这个问题.
这全是因为该死的计时器在每次屏幕方向更改时都设置了一个滴答事件.
要解决此问题,我只是将计时器绑定到一个变量,并在onSaveInstance()

I've managed to solve the problem.
It was all because of a damn timer which was setting a tick event on every screen orientation change.
To fix the issue I simply binded the timer to a variable, and called timer.cancel() in onSaveInstance()

现在我的内存泄漏消失了(如下所示):

Now my memory leaks are gone (as shown below):