不可访问内存 Java四种引用包括强引用,软引用,弱引用,虚引用

小结:

1、不可访问内存是指一组没有任何可访问指针指向的由计算机程序进行动态分配的内存块。

2、垃圾收集器能决定是否一个对象还是可访问的;任何被确定不可访问的对象将会被释放。

https://zh.wikipedia.org/wiki/不可访问内存

计算机科学中,不可访问内存是指一组没有任何可访问指针指向的由计算机程序进行动态分配的内存块。类似的,一个不可访问对象是指没有可访问引用型指向的动态分配对象。通俗来说,不可访问内存是程序无法直接访问的动态内存,同时也无法通过指针指向一个可访问的起始对象来进行访问。

动态内存分配的实现是采用了垃圾回收机制,在一个对象不可访问后,它会被回收。垃圾收集器能决定是否一个对象还是可访问的;任何被确定不可访问的对象将会被释放。在许多编程语言中(例如:JavaC#D语言Dylan)都使用了自动垃圾回收机制。

相反的,在动态内存分配机制中,当需要明确释放的内存变得不可访问时,此内存可以不再明确释放。在使用人工内存管理中,系统中的不可访问内存会导致内存泄漏

一些垃圾收集器使用弱引用。如果一个对象能够通过弱引用或者包含弱引用的链接,那么这个对象可以被称为弱访问。垃圾收集器能够把弱访问的对象图视为不可访问的,并且释放它。(反过来说,防止对象被当作垃圾收集的引用被称为强引用;通过只含有强引用的链接来访问的弱可访问对象是不可访问的。)一些垃圾回收的面向对象语言,例如JavaPython,拥有弱引用的特性。Java包java.lang.ref提供了软引用,弱引用和虚引用,产生了其他对象访问状态可软访问可虚访问

不可访问内存往往和软件老化有关。

参见

外部链接

A useful discussion can be found at Ethan Nicholas's Blog

Unreachable memory - Wikipedia https://en.wikipedia.org/wiki/Unreachable_memory

In computer scienceunreachable memory is a block of memory allocated dynamically where the program that allocated the memory no longer has any reachable pointer that refers to it. Similarly, an unreachable object is a dynamically allocated object that has no reachable reference to 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 a garbage 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. Many programming languages (for example, JavaC#DDylan) 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 explicitly deallocated. Unreachable memory in systems that use manual memory management results in a memory leak.

Some garbage collectors implement weak 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 be weakly reachable. The garbage collector can treat a weakly reachable object graph as unreachable and deallocate it. (Conversely, references that prevent an object from being garbage collected are called strong references; a weakly reachable object is unreachable by any chain consisting only of strong references.) Some garbage-collected object-oriented languages, such as Java and Python, feature weak references. The Java package java.lang.ref supports soft, weak and phantom references, resulting in the additional object reachability states softly reachable and phantom reachable.

Unreachable memory is often associated with software aging.

External links

Java四种引用包括强引用,软引用,弱引用,虚引用。 - 一步一个脚印,坚持 - 博客园
https://www.cnblogs.com/yw-ah/p/5830458.html

上一篇:关于浮动方面的相关知识点


下一篇:CSS3——文本属性