IDisposable, does it really matter

后端 未结 9 2866
予麋鹿
予麋鹿 2021-02-20 09:19

Coming from C/C++ a long time ago I still have a habit of ensuring that all resources are cleaned up correctly. I always ensure Dispose is called on IDisposable classes and impl

9条回答
  •  無奈伤痛
    2021-02-20 09:48

    Yes, Yes, Yes, It matters.

    I've been profiling an application recently that had never been profiled. It's just a Winforms application, no big deal, right?

    Wrong.

    By not implementing IDisposible and not de-referencing event handlers, the application was leaking memory like a sieve.

    The .NET Framework does not absolve you from cleaning up after yourself, it just makes it less likely that you'll break something if you don't.

    Spend an hour, profile your application with the ANTS Profiler. It's a free trial. If you don't see any memory leaks, then continue on your way. If you do, then it's because you were relying on the .NET Framework to be your crutch.

提交回复
热议问题