Hacker News new | ask | show | jobs
by candiodari 1260 days ago
Adding features to languages by anyone but the language designer doesn't work. It's unsupported, it affects too many other parts of the stack and leads to incredibly hard to spot bugs. You, or any project, can't do this.

Also: doing this means as soon as you start using predictable finalisation to close DB connections, or anything, your code stops being C# code. It can no longer be used except in a highly nontrivial environment. It depends, in an undeclared manner, on a nonstandard runtime.

So for open source code, or anything you're hoping to reuse: please don't do this.

If you want this, switch to C++, Swift or Rust, or some other language that has it built in.

1 comments

That is what using declarations and IDisposable are for.
Exactly. Idiomatic C# code does not depend on finalizers to release resources. Finalizers are typically only used as a last resort to prevent handle leaks, it is only memory deallocation that is nondeterministic.
And even then, SafeHandle is a much better option.

Memory deallocation can be done as deterministic as malloc/free via the native heap APIs.