Home > Mobile >  The activity not completely withdraw
The activity not completely withdraw

Time:11-28

In an activity to create a callback handler for receiving network news, in this activity created a Thead to asynchronous network, when waiting for the network to return to finish the activity, has triggered onDestory in this activity, but the handler is to pass the Message to the activity, the member variables don't really feel destroyed
But the adb shell dumpsys activity see have no this acitivity

Online some, because the activity using an anonymous inner class handler class object holds the activity quoted lead to memory overflow, the activity is not recycled

But I get rid of the handler and the network Thread in management class weakref a this activity to observe or has not been destroyed

CodePudding user response:

Depends on your specific implementation, the estimate is leaked, the activity did not release, thread didn't stop

CodePudding user response:

What did you do in the handler time-consuming operation, can cause a memory leak, you use a WeakReference also won't immediately recycling, wait until the next gc scan to this reference will be recycled,

CodePudding user response:

In onDestory mHandler. RemoveCallbacksAndMessages (null); !

CodePudding user response:

You must ensure that thread destroyed, the handler to remove or judgment of thread USES a while loop condition is set to false

CodePudding user response:

MHandler. RemoveCallbacksAndMessages (null); This sentence must call, or a memory leak

CodePudding user response:

OnDestroy inside to determine threads and handler has been destroyed
  • Related