Dispose question

后端 未结 7 1974
北荒
北荒 2021-02-14 02:51

I have a number of classes which have private member variables that implement IDisposable (timers, brushes, etc). Do I need to do anything to ensure these variables are cleaned

7条回答
  •  再見小時候
    2021-02-14 03:00

    1) You can use a Memory Profiler Tool, there are plenty around the web, the best i know being Reg Gate's ANTS Profiler.

    2) My rule of thumb is that events must always be unsubscribed, and disposable objects (Streams etc) will be disposed automatically if they're member variables and the object holding them gets destroyed. If you create a local disposable object in a method for example, you must dispose it, or just put it in a using statement and forget about it ;)

提交回复
热议问题