How do events cause memory leaks in C# and how do Weak References help mitigate that?

前端 未结 3 611
感情败类
感情败类 2020-11-28 08:32

There are two ways (that I know of) to cause an unintentional memory leak in C#:

  1. Not disposing of resources that implement IDisposable
  2. Re
3条回答
  •  被撕碎了的回忆
    2020-11-28 09:12

    Read Jon Skeet's excellent article on events. It's not a true "memory leak" in the classic sense, but more of a held reference that hasn't been disconnected. So always remember to -= an event handler that you += at a previous point and you should be golden.

提交回复
热议问题