2011-12-10 7 views
3

softreferences가 포함 된 weakhashmap에 데이터 객체를 넣어야합니다. "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"를 넣어해야

답변

3

나는 이것이 당신이

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

찾고있는 것을 생각하지만, 당신은 아마 참조 된 개체를 제거해야합니다 (또는 캐시 키와 함께 성장할지도에서 SoftRefence을 제거하기 위해 대기열을 추가 할 및 빈 softrefences.

0

당신이 부드러운 값을 지정할 수 있습니다 Guava's MapMaker 클래스를 한 번 봐 타고하는 SoftReference. 자신을 다시 구현하는 것보다 쉬운 방법입니다.

+0

나는 내장 클래스를 사용하고 있습니다. – CQM

관련 문제