欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

WeakReference,SoftReference 和 PhatomRefere

系統 2092 0

前幾天發了一篇關于垃圾收集的帖子,自己也不是這方面的專家,所以肯定有很多問題和錯誤,也請大家多多包涵和指教。

今天再進一步談一下這個幾個Reference吧。老實說,這幾個名詞我也是最近才聽說,平時也沒有實際使用過,但是確實在java 1.2就存在的,看來真的是學無止境啊。

  • softly reachable :The object is the referent of a SoftReference . The garbage collector will attempt to preserve the object as long as possible, but will collect it before throwing an OutOfMemoryError.
  • weakly reachable :The object is the referent of a WeakReference , and there are no strong or soft references to it. The garbage collector is free to collect the object at any time, with no attempt to preserve it.
  • phantom reachable :The object is the referent of a PhantomReference , and there are no strong, soft, or weak references to it. This reference type differs from the other two in that it isn't meant to be used to access the object, but as a signal that the object has already been finalized, and the garbage collector is ready to reclaim its memory.

在《Thinking in Java》第四版是如此描述:In the order of SoftReference, WeakReference, and PhantomReference, each one is "weaker" than the last and corresponds to a different level of reachability. Soft references are for implementing memory-sensitive caches. Weak references are for implementing "canonicalizing mappings"—where instances of objects can be simultaneously used in multiple places in a program, to save storage—that do not prevent their keys (or values) from being reclaimed. Phantom references are for scheduling pre-mortem cleanup actions in a more flexible way than is possible with the Java finalization mechanism.

在引入了這幾個引用之后,對象的生命周期【1】:

WeakReference,SoftReference 和 PhatomReference 淺析

上面這段代碼演示了幾種引用的特性:

  • PhantomReference 總是返回null
  • 垃圾收集之后 PhantomReference , WeakReference 都進去了queue,而 SoftReference 沒有。證明 SoftReference 生命周期更長。

下面這個例子來自《Thinking in Java》第四版,稍作修改:

這個例子比較有意思,每次執行,結果都會有一些差異。至于為什么,我也在研究之中,歡迎大家指教!

參考:

【1】 http://www.kdgregory.com/index.php?page=java.refobj

【2】 http://improving.iteye.com/blog/436311

WeakReference,SoftReference 和 PhatomReference 淺析


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 波多久久夜色精品国产 | 国产一区二区三区视频 | 欧美六九视频 | 天堂网中文字幕 | 黄色入口网站 | 一区久久 | 国产精品视频免费观看 | 爱久娱乐网| 国产在线91精品入口首页 | 久久久伊人色综合A片无码 国产精品区一区二区三 | 欧美乱码伦视频免费 | 91精品国产综合久久婷婷香蕉 | 中文字幕在线观看第一页 | 亚洲人成网站在线播放观看 | 日韩18视频在线观看 | 亚洲国产日韩在线一区 | 男女视频在线免费观看 | 91青青国产在线观看免费 | 成人欧美一区二区三区视频xxx | 日本精品a在线 | 色两性午夜视频免费观看 | 九九热这里 | 欧洲一级毛片 | 亚洲一区在线免费 | 中文字幕无线码一区二区三区 | 毛片a区| 日本免费观看官网 | 天堂在线网 | 四虎精品8848ys一区二区 | 精品国产乱码一区二区三 | 久久精品免费视频观看 | 99热热精品| 久久99国产亚洲精品观看 | 日韩三级中文字幕 | 国产成人啪精品视频免费网站软件 | t66y最新地址一地址二69 | 在线欧美日韩国产 | 色婷婷导航 | 色播在线永久免费视频网站 | 日本精品人妻无码免费大全 | 天天操天天射天天操 |