虚引用和对象的生命周期无关。
Phantom reference has nothing to do with the life cycle of an object.
弱引用、软引用和虚引用允许灵活的缓存,能够改进应用程序的内存特性。
Weak, soft, and phantom references can improve the memory characteristics of your application by allowing flexible caching.
而且,内存中的一个对象可以被多个引用(可以是强引用、软引用、弱引用或虚引用)引用。
Furthermore, an object in memory can be referenced by multiple references that could be strong, soft, weak, or phantom. Before proceeding further, let's look at some terminology.
弱引用和软引用都扩展了抽象的reference类(虚引用(phantomreferences)也一样,这将在以后的文章中介绍)。
Weak and soft references both extend the abstract reference class (as do phantom references, which will be discussed in a future article).
虚可及对象(phantomly reachable):不是强可及对象、软可及对象,也不是弱可及对象,已经结束的,可以通过虚引用访问的对象。
Phantomly reachable: an object that is not strongly, softly, or weakly reachable, has been finalized, and can be accessed through a phantom reference.
第二次,进程只是引用数据成员和虚函数。
The second time, the process simply references the data members and virtual functions.
如果函数是虚函数,并且调用是通过引用或者指针,编译器基于动态类型生成代码确定调用哪个版本。
If the function is virtual and the call is through a reference or pointer, then the compiler generates code to determine which version to run based on the dynamic type of the object.
每个对象都有一些附加字节,通用语言运行库用来管理对象,如对象的虚表指针和同步锁定引用。
Every object has some additional bytes that the common language runtime USES to manage the object, such as the object's virtual table pointer and a reference to a sync block.
内存开销非常小:基本上每个接口需要额外4个字节(对象实例数据里虚函数表指针),加上引用计数的4个字节。
Overhead in memory is very small: You basically have a 4- byte overhead per interface (the vtable pointers in the object's instance data) plus 4 bytes for the reference counter.
内存开销非常小:基本上每个接口需要额外4个字节(对象实例数据里虚函数表指针),加上引用计数的4个字节。
Overhead in memory is very small: You basically have a 4- byte overhead per interface (the vtable pointers in the object's instance data) plus 4 bytes for the reference counter.
应用推荐