3

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.

fadden
  • 51,356
  • 5
  • 116
  • 166
Ashraf Alshahawy
  • 1,139
  • 1
  • 14
  • 38

2 Answers2

6

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.

Joseph Roque
  • 5,066
  • 3
  • 16
  • 22
  • Thanks, I think the same rule you described applies if I have a viewHolder with an ImageView and I set this viewHolder to a converted view tag, then passing ConvertedView.viewHolder.ImageView to WeakReference – Ashraf Alshahawy May 15 '15 at 11:07
1

A weak reference is a reference that does not protect the referenced object from collection by a garbage collector. Without seeing your code it is not possible for me to say if what you have done has any issues.

I suggest that you have a look at the following post:

How to use WeakReference in Java and Android development?

Community
  • 1
  • 1
PaulT
  • 4,266
  • 2
  • 13
  • 15