java 四种内存_不可访问内存 Java四种引用包括强引用,软引用,弱引用,虚引用...
小結(jié):
1、不可訪問(wèn)內(nèi)存是指一組沒(méi)有任何可訪問(wèn)指針指向的由計(jì)算機(jī)程序進(jìn)行動(dòng)態(tài)分配的內(nèi)存塊。
2、垃圾收集器能決定是否一個(gè)對(duì)象還是可訪問(wèn)的;任何被確定不可訪問(wèn)的對(duì)象將會(huì)被釋放。
https://zh.wikipedia.org/wiki/不可訪問(wèn)內(nèi)存
在計(jì)算機(jī)科學(xué)中,不可訪問(wèn)內(nèi)存是指一組沒(méi)有任何可訪問(wèn)指針指向的由計(jì)算機(jī)程序進(jìn)行動(dòng)態(tài)分配的內(nèi)存塊。類似的,一個(gè)不可訪問(wèn)對(duì)象是指沒(méi)有可訪問(wèn)引用型指向的動(dòng)態(tài)分配對(duì)象。通俗來(lái)說(shuō),不可訪問(wèn)內(nèi)存是程序無(wú)法直接訪問(wèn)的動(dòng)態(tài)內(nèi)存,同時(shí)也無(wú)法通過(guò)指針指向一個(gè)可訪問(wèn)的起始對(duì)象來(lái)進(jìn)行訪問(wèn)。
動(dòng)態(tài)內(nèi)存分配的實(shí)現(xiàn)是采用了垃圾回收機(jī)制,在一個(gè)對(duì)象不可訪問(wèn)后,它會(huì)被回收。垃圾收集器能決定是否一個(gè)對(duì)象還是可訪問(wèn)的;任何被確定不可訪問(wèn)的對(duì)象將會(huì)被釋放。在許多編程語(yǔ)言中(例如:Java,C#,D語(yǔ)言,Dylan)都使用了自動(dòng)垃圾回收機(jī)制。
相反的,在動(dòng)態(tài)內(nèi)存分配機(jī)制中,當(dāng)需要明確釋放的內(nèi)存變得不可訪問(wèn)時(shí),此內(nèi)存可以不再明確釋放。在使用人工內(nèi)存管理中,系統(tǒng)中的不可訪問(wèn)內(nèi)存會(huì)導(dǎo)致內(nèi)存泄漏。
一些垃圾收集器使用弱引用。如果一個(gè)對(duì)象能夠通過(guò)弱引用或者包含弱引用的鏈接,那么這個(gè)對(duì)象可以被稱為弱訪問(wèn)。垃圾收集器能夠把弱訪問(wèn)的對(duì)象圖視為不可訪問(wèn)的,并且釋放它。(反過(guò)來(lái)說(shuō),防止對(duì)象被當(dāng)作垃圾收集的引用被稱為強(qiáng)引用;通過(guò)只含有強(qiáng)引用的鏈接來(lái)訪問(wèn)的弱可訪問(wèn)對(duì)象是不可訪問(wèn)的。)一些垃圾回收的面向?qū)ο笳Z(yǔ)言,例如Java和Python,擁有弱引用的特性。Java包可軟訪問(wèn)和可虛訪問(wèn)。
不可訪問(wèn)內(nèi)存往往和
參見(jiàn)
外部鏈接
Unreachable memory - Wikipedia https://en.wikipedia.org/wiki/Unreachable_memory
Incomputer science,unreachable memoryis a block ofmemoryallocated dynamicallywhere theprogramthat allocated the memory no longer has any reachablepointerthat refers to it. Similarly, anunreachable objectis a dynamically allocatedobjectthat has no reachablereferenceto it. Informally, unreachable memory is dynamic memory that the program can not reach directly, nor get to by starting at an object it can reach directly, and then following a chain of pointer references.
In dynamic memory allocation implementations that employ agarbage collector, objects are reclaimed after they become unreachable. The garbage collector is able to determine if an object is reachable; any object that is determined to no longer be reachable can be deallocated. Manyprogramming languages(for example,Java,C#,D,Dylan) use automatic garbage collection.
In contrast, when memory becomes unreachable in dynamic memory allocation implementations that require explicit deallocation, the memory can no longer be explicitlydeallocated. Unreachable memory in systems that use manual memory management results in a
Some garbage collectors implementweak references. If an object is reachable only through either weak references or chains of references that include a weak reference, then the object is said to beweakly reachable. The garbage collector can treat a weakly reachableobject graphas unreachable and deallocate it. (Conversely, references that prevent an object from being garbage collected are calledstrong references; a weakly reachable object is unreachable by any chain consisting only of strong references.) Some garbage-collectedobject-orientedlanguages, such asJavaandPython, feature weak references. TheJava packagesupports soft, weak and phantom references, resulting in the additional object reachability statessoftly reachableandphantom reachable.
Unreachable memory is often associated with
External links
Nicholas, Ethan (4 May 2006)."Understanding Weak References".java.net. Archived fromthe originalon 19 August 2010. Retrieved1 October2010.External link in|publisher=
Java四種引用包括強(qiáng)引用,軟引用,弱引用,虛引用。 - 一步一個(gè)腳印,堅(jiān)持 - 博客園
https://www.cnblogs.com/yw-ah/p/5830458.html
總結(jié)
以上是生活随笔為你收集整理的java 四种内存_不可访问内存 Java四种引用包括强引用,软引用,弱引用,虚引用...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 近20年基金平均年化收益率
- 下一篇: java字节输入与字符输入_Java中的