18 ms·
The .Net runtime already provides you the tools to implement RAII. The library exposes this functionality canonically with `IDisposable` [1] When you're done wi
by Arnavion 10y ago
The .Net runtime already provides you the tools to implement RAII. The library exposes this functionality canonically with `IDisposable` [1] When you're done with your object, you call `obj.Dispose()` on it.
Your language could automatically derive `IDisposable` (or any similar interface) in the same way for every type, and insert calls to `this.Dispose()` based on scope.
Of course the .Net library itself requires GC. You can't change that.
[1] https://msdn.microsoft.com/en-us/library/ms244737.aspx https://msdn.microsoft.com/en-us/library/ms244737.aspx
- kodfodrasz 10y agoI would not consider IDisposable as a true RAII solution, but that comes the closest