Question

I'm pretty new to programming so would just like to ask the following question regarding the .net built in stopwatch class using system.diagnostics in C#.

Does it automatically take care of garbage collection each time it is called or would I still have to implement garbage collection?

Regards

Was it helpful?

Solution

You never have to implement garbage collection.

You may have to manage resources. For that, check whether a Type implements IDisposable.
And when it does, use the instance in a using() {}block or implement IDisposable on your own class.

But the Stopwatch class is not IDisposable so in this case, no action is required.

OTHER TIPS

If you mean with garbage collection the process of tidying up the memory after using variables, methods etc., all .Net languages (and so even C#) take this for you.

You never have to implement garbage collection. That's the point if it.

If the class implements IDisposable then you can manage it resource wise with something like

using(MyDisposable myDisposable = new MyDisposable())
{
   myDisposable.DoSomething();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top