The Lint feature has been enhanced, causing a lint (warning) on handler

public class WeakRefHandler extends Handler {
private final WeakReference<IHandlerMessage> reference;
public WeakRefHandler(IHandlerMessage t) {
reference = new WeakReference<IHandlerMessage>(t);
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
IHandlerMessage iHandlerMessage = reference.get();
if (iHandlerMessage != null) {
iHandlerMessage.handleMessage(msg);
}
}
public interface IHandlerMessage {
void handleMessage(Message msg);
}
}

 
If you make a handler in main thread(UI Thread) then the thread refers to its activity or context.
message in message-queue refers to target handler therefore GC is not working sometimes if the message is stacked in its activity so memory leak will happen
 

Buy me a coffeeBuy me a coffee
카테고리: Android

0개의 댓글

답글 남기기

이메일은 공개되지 않습니다.