很明显,弱引用不再起作用。
返回指定弱引用的目标的当前代数。
Returns the current generation number of the target of a specified weak reference.
有时推荐的一个处理失效侦听器的方法是使用弱引用。
One approach that is sometimes suggested for dealing with lapsed listeners is to use weak references.
比如说,WPF严重倚赖于弱引用来实现数据绑定技术。
For example, it heavily relies on weak references for its data-binding technology.
一点弱引用是指一个对象不强迫它留在记忆里。
The point of a weak reference is to refer to an object without forcing it to stay in memory.
如果已经分配了最低数量的对象,则对象的弱引用被放置到队列中。
If the minimum number of objects is already allocated, then a weak reference to the object is enqueued.
以前的一篇文章“用弱引用堵住内存泄漏”给出了一些有用的技巧。
A previous article, "Plugging memory leaks with weak references," offers some helpful techniques.
在这种情况下,解决办法就是也将链接列表中的链接更改 为弱引用。
The solution in this case is to change the links in the linked list to also be weak references.
从以上是否能看出,一个对象不能同时具有软引用和弱引用?
From above shall we say that an object can't have a soft reference and a weak reference at the same time?
如以下示例所示,弱引用和软引用都是解决内存泄露的强大工具。
As the following example shows, weak references and soft references are powerful tools for fixing memory leaks.
弱引用是对一个对象(称为referent)的引用的持有者。
A weak reference is a holder for a reference to an object, called the referent.
向列表中添加链接之后,被清除的弱引用的数量将从较大的数更改为完全没有。
After adding the linkage to the list, the number of weak references cleared changes from a large number to none at all.
在短周期对象销毁后,长周期对象对短周期对象的弱引用依然会长久保留下来。
The weak reference from the long-lived object to the short-lived object is kept long after the short-lived object has been destroyed.
仅在必要时使用长弱引用,因为在终止后对象的状态是不可预知的。
Use long weak references only when necessary as the state of the object is unpredictable after finalization.
通过在EVTK中绘制被清除的弱引用的图,可以证实该问题,如图17所示。
The problem can be verified by plotting the weak references cleared in the GC and Memory Visualizer, as shown in Figure 17.
使用弱引用后,可以维持对referent的引用,而不会阻止它被垃圾收集。
With weak references, you can maintain a reference to the referent without preventing it from being garbage collected.
请注意该方法如何用do -while循环来处理队列中可能存在的弱引用。
Notice how this method accounts for possible weak references in the queue with the do-while loop.
弱引用、软引用和虚引用允许灵活的缓存,能够改进应用程序的内存特性。
Weak, soft, and phantom references can improve the memory characteristics of your application by allowing flexible caching.
弱引用允许应用程序访问对象,同时也允许垃圾回收器收集相应的对象。
A weak reference permits the garbage collector to collect the object while still allowing the application to access the object.
这些图持有弱引用,允许连接这样的被跟踪对象在只有方面引用它们的时候,被垃圾收集掉。
These maps hold weak references to allow tracked objects like connections to be garbage collected when they are referenced only by the aspect.
弱引用有时会错误地用于取代软引用,用于构建缓存,但是这会导致差的缓存性能。
Weak references are sometimes mistakenly used instead of soft references for building caches, but this will result in poor caching performance.
弱引用有两个构造函数:一个只取referent作为参数,另一个还取引用队列作为参数。
Weak references have two constructors: one takes only the referent as an argument and the other also takes a reference queue.
因为垃圾回收器是一个优先级很低的线程,所以弱引用对象也不一定会马上就会被回收。
GC is a thread of very low priority, so a weak reference object may not be collected immediately.
弱引用告诉垃圾收集器如果某个对象除了弱引用之外没有其他任何引用,则应该收集该对象。
Weak references tell the garbage collector that it should collect an object if there are no references to it other than the weak reference.
弱引用特别适合以下对象:占用大量内存,但通过垃圾回收功能回收以后很容易重新创建。
Weak references are useful for objects that use a lot of memory, but can be recreated easily if they are reclaimed by garbage collection.
而且,内存中的一个对象可以被多个引用(可以是强引用、软引用、弱引用或虚引用)引用。
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.
哪怕及时释放掉了实际的对象,但WPF的弱引用数组还是会继续持有引用,这就导致了内存泄漏。
Even when the actual objects are being released in a timely manner, WPF's arrays of weak references hang around and under stress become the memory leak.
弱引用构成了这样的一个策略的基础,但是还有其他一些机制,并且所要使用的策略取决于环境。
Weak references form the basis of one such policy, but there are others, and which policy to use is based on circumstance.
正如弱引用一样,软引用也可创建为具有一个相关的引用队列,引用在被垃圾收集器清除时进入队列。
Just as with weak references, a soft reference can be created with an associated reference queue, and the reference is enqueued when it is cleared by the garbage collector.
WeakHashMap的实现展示了弱引用的一种常见用法——一些内部对象扩展WeakReference。
The implementation of WeakHashMap illustrates a common idiom with weak references — that some internal object extends WeakReference.
应用推荐