Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created October 19, 2013 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/7054732 to your computer and use it in GitHub Desktop.
Save Fhernd/7054732 to your computer and use it in GitHub Desktop.
Demostración de uso del método SuppressFinalize de GC en C#.
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