Weak reference benefits

前端 未结 3 1133
悲&欢浪女
悲&欢浪女 2020-11-30 21:00

Can someone explain the main benefits of different types of references in C#?

  • Weak references
  • Soft references
  • Phantom references
  • Str
3条回答
  •  青春惊慌失措
    2020-11-30 21:57

    MSDN has a good explanation of weak references. The key quote is at the bottom where it says:

    Avoid using weak references as an automatic solution to memory management problems. Instead, develop an effective caching policy for handling your application's objects.

    Every time I've seen a WeakReference in the wild, it's been used as an automatic solution to memory management problems. There are likely better solutions to your application's problems.

提交回复
热议问题