首页 \ 问答 \ Android:传递WeakReference作为参数(Android: passing WeakReference as a parameter)

Android:传递WeakReference作为参数(Android: passing WeakReference as a parameter)

我在我的(Obj_A)中为ImageView使用WeakReference,并且将此ImageView WeakReference传递给另一个将其分配给ImageView变量(但不是WeakReference)的对象(Obj_B),因此接收方ImageView变量将具有WeakReference的性质?

我希望我能够正确地塑造我的问题,并且我希望你明白我的意思。


I'm using a WeakReference for ImageView in my (Obj_A), and I pass this ImageView WeakReference to another object (Obj_B) that assign it to an ImageView variable (But not a WeakReference as well), so will the receiver ImageView variable have the nature of the WeakReference?

I hope I managed to mold my question correctly, and I hope you understand what I mean.


原文:https://stackoverflow.com/questions/30238193
更新时间:2023-01-23 17:01

最满意答案

不,您Obj_B中的ImageView不会是WeakReference。 WeakReference允许你以一种方式存储一个对象的引用,如果这个对象在任何地方没有其他的“强”引用,它将被垃圾收集。 通过移除Obj_B中的WeakReference包装器,您现在正在接受WeakReference管理的对象并存储您自己的强引用。


No, your ImageView in Obj_B will not be a WeakReference. A WeakReference allows you to store a reference to an object in such a way that if that object has no other "strong" references anywhere, it will be garbage collected. By removing the WeakReference wrapper in Obj_B, you're now taking the object that your WeakReference was managing and storing your own strong reference to it.

相关问答

更多