When should weak references be used?

后端 未结 4 1620
南方客
南方客 2020-12-08 16:21

I recently came across a piece of Java code with WeakReferences - I had never seen them deployed although I\'d come across them when they were introduced. Is this something

4条回答
  •  情话喂你
    2020-12-08 16:57

    A good question to ask when considering use of a WeakReference is how one would feel if the weak reference were invalidated the instant no strong references existed to the object. If that would make the WeakReference less useful, then a WeakReference is probably not the best thing to use. If that would be an improvement over the non-deterministic invalidation that comes from garbage-collection, then a WeakReference is probably the right choice.

提交回复
热议问题