Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java, convert object to softreference

I need to put a data object into my weakhashmap containing softreferences. How do I convert my "Drawable" object into a softreference?

WeakHashMap <String, SoftReference<Drawable>> tempPulled = new WeakHashMap<String,     SoftReference<Drawable>>();
Drawable pulled = BitmapDrawable.createFromResourceStream(null, null, conn.getInputStream(), "galleryImage", options);
SoftReference<Drawable> sPulled;            
tempPulled.put(id, pulled);

tempPulled should be putting "sPulled" , the softreference

like image 253
CQM Avatar asked Dec 11 '25 19:12

CQM


1 Answers

I think this is what you are looking for

SoftReference<Drawable> sPulled = new SoftReference<Drawable>(pulled);            

But you probably want to add a queue to remove the SoftRefence from the map should the referenced object be removed (or your cache will grow with keys and empty softrefences.

like image 181
Roger Lindsjö Avatar answered Dec 13 '25 07:12

Roger Lindsjö



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!