Fixed runnable memory leaks

This commit is contained in:
M66B
2024-07-07 16:59:23 +02:00
parent 9a7bb254cc
commit b3cc164eef
7 changed files with 0 additions and 344 deletions

View File

@@ -24,12 +24,8 @@ import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.Map;
import java.util.WeakHashMap;
public class FixedLinearLayout extends LinearLayout {
public FixedLinearLayout(Context context) {
super(context);
@@ -56,46 +52,4 @@ public class FixedLinearLayout extends LinearLayout {
return false;
}
}
private Map<Runnable, Runnable> mapRunnable = null;
@NonNull
private Map<Runnable, Runnable> getMapRunnable() {
if (mapRunnable == null)
mapRunnable = new WeakHashMap<>();
return mapRunnable;
}
@Override
public boolean post(Runnable action) {
Runnable wrapped = new RunnableEx("post") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.post(wrapped);
}
@Override
public boolean postDelayed(Runnable action, long delayMillis) {
Runnable wrapped = new RunnableEx("postDelayed") {
@Override
protected void delegate() {
action.run();
}
};
getMapRunnable().put(action, wrapped);
return super.postDelayed(wrapped, delayMillis);
}
@Override
public boolean removeCallbacks(Runnable action) {
Runnable wrapped = getMapRunnable().get(action);
if (wrapped == null)
return super.removeCallbacks(action);
else
return super.removeCallbacks(wrapped);
}
}