handler.sendMessage(Message ) -> sendMessageAtTime(Message msg, long uptimeMillis)
-> enqueueMessage(queue, msg, uptimeMillis)
private boolean enqueueMessage(MessageQueue queue, Message msg, long uptimeMillis)
// 把handler赋值给了message,所以message持有handler的引用
msg.target = this;
if (mAsynchronous) {
msg.setAsynchronous(true);
}
return queue.enqueueMessage(msg, uptimeMillis);
}
message持有handler的引用, handler是非静态内部类的时候会持有activity的引用,当activity关闭后,如果还有message未处理,会导致activity的引用无法回收
网友评论