C# Finalizers are not destructors and Dispose is not a pattern

Nuestro buen amigo Javier Caceres nos comparte su artículo:

C# Finalizers are not destructors and Dispose is not a pattern

The terms Finalizers, Destructors and Dispose methods are used interchangeably making developers ignore their proper usage. Managed environments can clean-up most of the RAM memory you use, except for unmanaged resources, so here is where Finalizers and Dispose methods come into play.

This native-managed impedance mismatch has led engineers think that all the “cleaning code” is created and called automatically. The fact that unmanaged resources are basic building blocks so it’s important to underline their differences and oversee their correct usage. Simply put, Finalizers are implicit resource clean up, which means that your write the Finalize method and the Garbage Collector will probably call it. Finalizers use destructors’ syntax, so we can not call them directly.

Finalizers work well within managed environments, but while working with unmanaged resources you need to clean up resources exactly when you finish using them to improve performance. Having into account that our applications use databases, files and other resources it’s important to know how to do it.

clip_image001

Ver más aquí.
Gracias.

Fernando García Loera (Community Program Manager – Latin America Region)

Icono Ferglo 40x116twitter 40x40RSS 40x40facebook 40x116linkedin40x40xbox 40x40

Que es un MVP? / Tips para ser MVP