Replies: 1 comment 3 replies
-
C# destructor maps to finalizers of dotnet runtime. Nowadays, finalizers are useless most of the time. Finalizer have many issues, e.g.:
So, for most developers, forget about finalizer, you won't need it. You don't need finalizer for managed objects. For the rare cases where you do want something like finalizer but does its job, e.g. wrapping native code resources/objects, you should use SafeHandle instead, which utilizes something called Critical Finalizer internally. Note it is not for average developer; there are many rules and cautions to really make it work as expected. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The destructor of a class after implementing IDisposable is never called. Does this mean that the instance GC of this class will not release resources? I'm not sure if this guess is correct? The attached file is a test case. Currently, I am encountering the problem that resources cannot be released in my project. The memory continues to grow and the GC does not release related resources. The code is similar to the test case. I don’t know how to solve it now?
Wpf.ResourceCleanup.zip
Beta Was this translation helpful? Give feedback.
All reactions