• tias@discuss.tchncs.de
      link
      fedilink
      arrow-up
      7
      ·
      7 hours ago

      You can’t, not in e.g. Java or C#.

      C++ and Rust are the only languages I know of that do this right.

        • tias@discuss.tchncs.de
          link
          fedilink
          arrow-up
          2
          ·
          4 hours ago

          Maybe you’re thinking of IDisposable with the using keyword. The problem with that is that you have to remember to use it in every call site. Nothing stops a caller from writing var x = new Foo() and walking away.