BBS1692327725138
2023-08-31 15:26 发表了评论 感谢derry老师的解答
根据anr日志是ViewModel里面的问题 viewModel clear时有一把锁 不使用viewModel 直接依赖仓库就好了
怀疑是流close的时候有问题 但是都是用的lifeCyleScope
viewModel clear 源码
@MainThread
final void clear() {
mCleared = true;
// Since clear() is final, this method is still called on mock objects
// and in those cases, mBagOfTags is null. It'll always be empty though
// because setTagIfAbsent and getTag are not final so we can skip
// clearing it
if (mBagOfTags != null) {
synchronized (mBagOfTags) {
for (Object value : mBagOfTags.values()) {
// see comment for the similar call in setTagIfAbsent
closeWithRuntimeException(value);
}
}
}
// We need the same null check here
if (mCloseables != null) {
synchronized (mCloseables) {
for (Closeable closeable : mCloseables) {
closeWithRuntimeException(closeable); 怀疑是这里耗时了
}
}
}
onCleared();
}
anr日志
| held mutexes= “mutator lock”(shared held)
at java.util.LinkedHashMap$LinkedHashIterator.hasNext(LinkedHashMap.java:413)
at androidx.lifecycle.ViewModel.clear(ViewModel.java:185)
locked <0x0c88a1b3> (a java.util.LinkedHashSet)
at androidx.lifecycle.ViewModelStore.clear(ViewModelStore.java:62)
2023-08-18 13:24 发布提问 App长期使用造成anr
关注0
收藏0
点赞0
个人成就
发布问题数:
1 个
发布文章数:
0 篇
答案被采纳数:
0 次
评论次数:
0 次
帮助
关注数: 关注的问题和作者的总数
收藏数: 收藏的问题和文章的总数