What are ways to solve Memory Leaks in C#

前端 未结 10 1767
生来不讨喜
生来不讨喜 2021-02-14 14:50

I\'m learning C#. From what I know, you have to set things up correctly to have the garbage collector actually delete everything as it should be. I\'m looking for wisdom learn

10条回答
  •  离开以前
    2021-02-14 15:43

    What are the best ways to get things deleted?

    NOTE: the following works only for types containing unmanaged resources. It doesn't help with purely managed types.

    Probably the best method is to implement and follow the IDisposable pattern; and call the dispose method on all objects implementing it.

    The 'using' statement is your best friend. Loosely put, it will call dispose for you on objects implementing IDisposable.

提交回复
热议问题