Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]LoopMonitor内存问题 #203

Closed
Colibrow opened this issue Apr 21, 2019 · 8 comments
Closed

[Bug]LoopMonitor内存问题 #203

Colibrow opened this issue Apr 21, 2019 · 8 comments

Comments

@Colibrow
Copy link

异常类型:bug

matrix版本: 0.5.1

gradle版本: 3.0.1

问题描述:LoopMonitor对于内存的印象

因为LoopMonitor在监听的时候会加入一个printer进行日志的输出

Looper.getMainLooper().setMessageLogging(printer = new Printer() {
            @Override
            public void println(String x) {
            	...
            }
        });

所以一旦有多个message快速进入的时候会存在内存不停增加的问题
profile

@changelcai
Copy link
Collaborator

changelcai commented Apr 21, 2019

boolean hasPrinter = false;
Looper looper = Looper.getMainLooper();
Handler handler = new Handler(looper);
looper.setMessageLogging(hasPrinter ? new Printer() {
    @Override
     public void println(String x) {

     }
} : null);
for (int i = 0; i < 10 * 10000; i++) {
    handler.post(runnable);
}

是的,之前测试过上面的代码,确实会存在内存抖动的情况,比较极端,主要还是因为这里有个字符串拼装。

if (logging != null) {
    logging.println(">>>>> Dispatching to " + msg.target + " " +  msg.callback + ": " + msg.what);
}

暂时没有想到更完美的方案。有什么好的建议吗

@lijiankun24
Copy link

TraceCanary 是使用 Looper.getMainLooper().setMessageLogging() 的方式实现卡顿帧率检测的吧?为什么我看有的地方说是使用 Choreographer 的方式实现的呢?是版本差异吗

@changelcai
Copy link
Collaborator

老版本是用Choreographer,现在是依赖Looper.getMainLooper().setMessageLogging()

@lijiankun24
Copy link

@changelcai 这种差异的原因是?

@sailor1861
Copy link

@changelcai 能否解释下,为啥改用Looper.getMainLooper().setMessageLogging()方案; 有啥考虑呢?

@chinacuizichao
Copy link

@changelcai 能否解释下,为啥改用Looper.getMainLooper().setMessageLogging()方案; 有啥考虑呢?

1 similar comment
@buyi
Copy link

buyi commented May 28, 2020

@changelcai 能否解释下,为啥改用Looper.getMainLooper().setMessageLogging()方案; 有啥考虑呢?

@aishang5wpj
Copy link

aishang5wpj commented Dec 21, 2020

一直没人回答,小白盲猜一下,可能有几点原因:

  1. Choreographer 只是负责ui绘制部分的监听,ui卡顿不一定是绘制卡顿引起的,有可能是主线程耗时操作引起的ui卡顿,比如两次绘制之间有10个msg,Choreographer只能监听到这10个msg造成了卡顿,但是没办法定位到具体是哪个msg导致的卡顿,如果用looper来监听,就可以准确监听到是哪个msg导致的卡顿
  2. 静态页面可能导致帧率较低,因此帧率低可能并不真的是卡顿,所以用这个统计出来的不是很准
  3. 其次是不同设备帧率标准可能不一样,现在很多设备有120hz、90hz、60hz,模拟器有的是30hz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants