2011-12-10 7 views
3

softreferencesを含む弱いハッシュマップにデータオブジェクトを配置する必要があります。私の "Drawable"オブジェクトをどのようにしてソフトリファレンスに変換するのですか?Java、オブジェクトを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は "sPulled" を置くべきである、softreference

答えて

3

私は、これはあなたが

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

探しているものだと思う。しかし、あなたはおそらくマップからSoftRefenceを削除するためにキューを追加したい参照されたオブジェクトを削除する必要があります(または、あなたのキャッシュキーと一緒に成長し、空のソフトレフェンス

0

は、あなたがソフト値を指定することができますGuava's MapMakerクラス、見てみましょう。自分でそれを再実装するよりも簡単です。

+0

私は組み込みクラスを使用しています。 – CQM

関連する問題