Created
October 19, 2013 11:28
-
-
Save Fhernd/7054732 to your computer and use it in GitHub Desktop.
Demostración de uso del método SuppressFinalize de GC en C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
public class ContadorIndestructible | |
{ | |
private Stopwatch cronometro; | |
public ContadorIndestructible () | |
{ | |
cronometro = Stopwatch.StartNew (); | |
Console.WriteLine ("Se ha instanciado un objeto."); | |
// Aquí se marca la instancia actual para que el recolector de basura | |
// ignore la liberación de recursos asociados a esta instancia. | |
GC.SuppressFinalize (this); | |
} | |
public void MostrarDuracion () | |
{ | |
Console.WriteLine ("La instancia {0} ha tenido una duración de: {1}.", this, cronometro.Elapsed); | |
} | |
~ContadorIndestructible () | |
{ | |
Console.WriteLine ("Se iniciado la finalización del objeto."); | |
cronometro.Stop (); | |
Console.WriteLine ("La instancia {0} ha tenido una duración de: {1}.", this, cronometro.Elapsed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment