DEV Community

Discussion on: How does your language handle memory?

 
mortoray profile image
edA‑qa mort‑ora‑y

It's considered one of the strong points of C++ that you don't need to manually cleanup resources of any kind, it doesn't make memory a special case.

The Dispose pattern is a contrast to this. Like C, all resources, except memory, must be manually released. Automatic "memory" management doesn't solve any of the problems of other resources, something that C++ does actually solve.

All resources are part of this discussion, and if we just ignore them it isn't a fair comparison between how languages handle it.

Thread Thread
 
galdin profile image
Galdin Raphael

aaah you're contrasting it with C++. Makes sense.

C# doesn't the C++ concept of automatic storage. In C# everything that's a reference-type is garbage collected. Garbage collection means that you don't have control over when the object is disposed. It doesn't generally matter, but sometimes it does. Like in files for example. This is where the disposable pattern comes in.

C++ doesn't have a runtime garbage collector. So things are different there. One can tell when a resource is going to be disposed (i.e. when an object's destructor will be called) unlike in C#. So there's no need for a disposable pattern here.