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
 

카테고리: 미분류

0개의 댓글

답글 남기기

Avatar placeholder

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다.