My question is simple, why GC can't figure it out that timer
object in the main
should be garbage collected along with the timer
inside TestTimer
and associated EventHandler
?
Why am I continously getting console.Writeline
output?
class Program
{
public static void Main()
{
TestTimer timer = new TestTimer();
timer = null;
GC.Collect();
GC.WaitForPendingFinalizers();
Console.ReadKey();
}
}
public class TestTimer
{
private Timer timer;
public TestTimer()
{
timer = new Timer(1000);
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Start();
}
private void timer_Elapsed(Object sender, ElapsedEventArgs args)
{
Console.Write("\n" + DateTime.Now);
}
}
Following compounds cannot be detected: Compounds which are too volatile: most C1-C4 aliphatic hydrocarbons, methanol, methanal. Some important (odorous) inorganic compounds like hydrogen sulphide and ammonia. To analyse these compounds a specific analytical method is required (GC or colorimetric methods)
A GC/MS system scans the samples continuously throughout the separation and, ultimately, the chromatogram shows the retention times. The chromatogram peak is analyzed by the mass spectrometer which leads to the identification of the separated components.
Utilisation of GC creates a high risk of thermal degradation of vitamins, even when derivatisation is done prior to GC separation. An example of this is GC-based vitamin K applications, which, due to high retention times and possible on-column degradation, are not very well suited for GC analysis.
The principal limitation of gas chromatographic application is given by an insufficient volatility of the species to be separated. Elevated temperatures have to be applied if the application range is to be extended and to achieve steep peak profiles, i.e. low detection limits at high resolution.
Don't depend on the GC, use the Dispose pattern to properly dispose the TestTimer
(which then should dispose the Timer
).
However, what happens is that the timer keeps itself alive by getting a GC handle on itself. Read this blog post:
http://nitoprograms.blogspot.com/2011/07/systemthreadingtimer-constructor-and.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+blogspot%2FOlZtT+%28Nito+Programming%29
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With