Java?????????????
???????????? ???????[ 2013/6/6 9:45:21 ] ????????
???????????Soft Reference??????????????н???????ù??????е???治?????????????????棬?????????????????????????????????????Щ?????????????Java ???OutOfMemory?????????????null????????????????Щ???????????棬???Cache????????????????????????????OutOfMemory????
???????????????????????
import java.lang.ref.SoftReference;
public class softReference {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
A a = new A();
//???a
a.test();
//???????a???????????soft?????????????????????
SoftReference sr = new SoftReference(a);
a = null;
//?′????
if (sr != null) {
a = (A)sr.get();
a.test();
} else {
//GC???????棬?????a???????????????
a = new A();
a.test();
a = null;
sr = new SoftReference(a);
}
}
}
class A {
public void test() {
System.out.println("Soft Reference test");
}
}
?????????ü??????????Java???????????????棬?????????????????????????????????????????Щ??????????????????????????ò????????????????????ü??????????????????????????????б?????Щ?????????????????????????Ч????????????磺????????????????????????????????????????????????й????з?????仯??????????′????????????????????????????鷳????Щ????????????????????á?
????????????????????Android???????????
????Java?е?SoftReference
????????????????á???????????????????????????????????????????????????????????????????????Щ???????檔??????????????л??????????????????????á????????????????????е??????檔????????????????й????????????????
????SoftReference?????????????????????????Java?????????????????????????????????????????Java??????????????????SoftReference??????????Java??????????ú??????????????Java??????????SoftReference????????get()????????Java?????????á???????????????????Java???????get()??????????null
??????Map??????????????Bitmap????
<SPAN style="FONT-SIZE: 18px"><STRONG style="BACKGROUND-COLOR: rgb(255??255??255)">Map<String?? SoftReference<Bitmap>> imageCache = new new HashMap<String?? SoftReference<Bitmap>>();
//??????Bitmap????
Bitmap bitmap = BitmapFactory.decodeStream(InputStream);
//???????Bitmap????
SoftReference<Bitmap> bitmapcache = new SoftReference<Bitmap>(bitmap);
//???????Map????仺??
imageCache.put("1"??softRbitmap);
..
.
//???????????????Bitmap????
SoftReference<Bitmap> bitmapcache_ = imageCache.get("1");
//???Bitmap?????????????治??Bitmap?????????????
Bitmap bitmap_ = bitmapcache_.get();</STRONG></SPAN>
??????????????????????????????????????????????sdcard????????????л?????Щ?????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11