与弱引用一样,软引用通过利用垃圾收集器在作出缓存回收决策方面的帮助,有助于防止应用程序出现对象游离。
Soft references, like weak references, can help applications prevent object loitering by enlisting the aid of the garbage collector in making cache eviction decisions.
当数组用于实现诸如堆栈或环形缓冲区之类的数据结构时,会出现另一种形式的对象游离。
Another form of object loitering arises when arrays are used to implement data structures such as stacks or circular buffers.
修复这种情况下的对象游离的方法是,当对象从堆栈弹出之后,就消除它的引用,如清单3中注释掉的行所示。
The cure for object loitering in this case is to null out the reference after popping it from the stack, as shown in the commented-out line of code in Listing 3.
应用推荐