First of all, make sure you know which of the classes you use implement
System.IDisposable
and call
System.IDisposable.Dispose
on all instances. Also, there are types which implement some
Dispose
methods not related to this interface; check it up.
Also, make sure you understand stuff related to possible memory/resource leaks I explain in my past answers:
Memory leak in WPF DataBinding[
^],
Memory management in MDI forms[
^],
Best way to get rid of a public static List Causing an Out of Memory[
^],
deferring varirable inside the loop can cuase memory leak?[
^],
Garbage collectotion takes care of all the memory management[
^].
[EDIT]
Let's see. This is a copy from your code in comment:
player = null;
}
if (player != null)
{
player.Dispose();
}
This is an apparent possibility of a leak. Do I even have to explain why? You should not assign an object to null.
And this is is just wrong
using (player) {}
And this is
just crime (against yourself?):
try {
}
catch (Exception genericException)
{
}
You are completely blocking propagation of exception, and even without any handling. You should not do exception handling at this point at all, let it propagate. Learn how exceptions work.
—SA