开发者

Are multiple weak references to the same object cleared in groups?

If I have multiple weak references pointing at the same object, and no stron开发者_JS百科g references are around. Can I be sure both weak references are intact when one of them returns the object?


WeakReference wr1 = new WeakReference(objX);
...//somewhere else
WeakReference wr2 = new WeakReference(objX);

Now:

  1. If at a moment wr1.get() returns non-null, then wr2.get() will return non-null too.
  2. But wr1 and wr2 object themselves are gc-ed independently, their gs-paths are independent of each other and most importantly independent of objX.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜