AndroidUtilCode icon indicating copy to clipboard operation
AndroidUtilCode copied to clipboard

内存泄漏

Open shouzhong opened this issue 3 years ago • 1 comments

Describe the bug

这部分demo代码会内存泄漏

The code of bug

https://github.com/Blankj/AndroidUtilCode/blob/master/feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/mvp/MvpView.java#L46

private void measure() {
    ThreadUtils.runOnUiThreadDelayed(new Runnable() {
        @Override
        public void run() {
            float textWidth = Layout.getDesiredWidth(mvpMeasureWidthTv.getText(), mvpMeasureWidthTv.getPaint()) + SizeUtils.dp2px(16);
            float textWidth2 = mvpMeasureWidthTv.getPaint().measureText(mvpMeasureWidthTv.getText().toString()) + SizeUtils.dp2px(16);
            LogUtils.i(mvpMeasureWidthTv.getWidth(), textWidth, textWidth2);
            mvpMeasureWidthTv.setText(mvpMeasureWidthTv.getText().toString() + i);
            measure();
        }
    }, 1000);
}

shouzhong avatar Aug 05 '22 07:08 shouzhong

可以改成View.postDelayed或者其他方式

shouzhong avatar Aug 05 '22 07:08 shouzhong