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개의 댓글