zandy icon indicating copy to clipboard operation
zandy copied to clipboard

Activity memory leak caused by anonymous threads

Open cuixiaoyiyi opened this issue 2 years ago • 0 comments

An anonymous inner class will hold a reference to the this pointer of the outer class and will not be released until the thread ends.

It will hold the Activity and prevent its timely release.

com.gimranov.zandy.app.MainActivity:
 void onClick()
 void onNewIntent()
 void toastError()  // ApplicationContext instead

The anonymous thread can be replaced by static class with weak references of activity.

cuixiaoyiyi avatar Aug 29 '22 15:08 cuixiaoyiyi