垃圾收集和毕加索的问题 [英] Issues with garbage collection and Picasso

查看:154
本文介绍了垃圾收集和毕加索的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Google Maps Marker的InfoWindow中设置一个ImageView,并将这个答案中的代码完全复制,除了我的InfoWindowAdapter不是一个匿名的内部类(它只是活动的内部类)。这是以前的工作,但由于某种原因,它已停止工作 - 回调中的onSuccess方法没有被调用,所以InfoWindow仅在第二次打开时显示图像。



查看毕加索的日志,我得到类似于的主要消息[R20] + 374ms target收集垃圾。我想这可能是因为回调得到gc'd,并试图使它最终,并保存在一个类字段中的对象(这些工作都没有,虽然也许我做错了吗?)。



这里可能会发生什么,我该如何解决?在引用回调的错误消息中是 target ,还是它可能指向作为参数传递给回调构造函数的标记?



另一个奇怪的是,有时图像在InfoWindow第一次打开的时候被正确加载 - 我试图找出原因,但基本上我有很多标记以及它们的图像是否正确加载或者第一次出行似乎不一致。有一些(大多数)在InfoWindow第一次打开时似乎无法正确加载。

这是在一堆代码合并到该活动之后,那么它会成为记忆吗? (现在有更多的处理比我没有这个问题的时候完成了)



[edit 2]我的问题与滑翔!可能是垃圾回收?

解决方案

我对这个答案并不熟悉,但 Target

这是因为毕加索持有目标实例与弱引用。



您应该在毕加索以外的地方持有 Target 实例。



查看此问题: https:// github.com/square/picasso/issues/352


I am trying to set an ImageView in a Google Maps Marker's InfoWindow and have copied the code from this answer pretty exactly, except that my InfoWindowAdapter isn't an anonymous inner class (it's just an inner class of the activity). This was working before, but for some reason it has stopped working - the onSuccess method in the Callback doesn't get called, so the InfoWindow only displays the image the second time it is opened.

Looking at the logs for Picasso I'm getting messages similar to Main canceled [R20]+374ms target got garbage collected. I figured this might be because the Callback is getting gc'd, and tried making it final, and also saving the object in a class field (neither of these worked, although maybe I was doing it wrong?)

What could be happening here, and how can I fix it? Is that target in the error message referring to the Callback, or could it be referring to the marker that gets passed as an argument to the Callback's constructor?

Another odd thing is that sometimes the images are loaded correctly when the InfoWindow is first opened - I'm trying to find out why, but basically I have a lot of markers and whether their images load correctly or not on the first go seems to be inconsistent. There are some (the majority) that never seem to load correctly when the InfoWindow is first opened.

[edit] This was after a bunch of code was merged into that activity, so could it be a memory thing? (there's more processing done now than there was when I wasn't having this problem)

[edit 2] I'm having exactly the same issue with Glide!! Probably garbage collection?

解决方案

I'm not familiar with that answer, but Target could be gc'ed when you do not hold strong reference to that.

It's because Picasso holds Target instance with weak reference.

You should hold Target instance somewhere outside of Picasso.

Check this issue: https://github.com/square/picasso/issues/352

这篇关于垃圾收集和毕加索的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆