Search code examples
.netraii

RAII-Wrapper for .NET?


Is it theoretically possible to create a RAII-Wrapper for .NET? As a long time C++ programmer I hate to manage object lifetime myself again. The Dispose-Pattern is IMHO nothing but a bad joke compared to the ease of use of RAII, especially as it forces the user to handle the implementation detail (Dispose) of an object and the class to become IDisplosable itself…


Solution

  • Dispose is only for unmanaged resources. For managed resources, you have to do nothing since the garbage collector takes care of it (and doesn't even allow you to do deterministic release of resources anyway).

    So what exactly do you want to achieve?