Please see my comment. Detecting a leak is not easy, and even understanding what a leak is is not so simple when it comes to managed memory. Please see my past answers explaining managed and unmanaged memory leaks:
Garbage collectotion takes care of all the memory management[
^],
deferring varirable inside the loop can cuase memory leak?[
^],
Best way to get rid of a public static List Causing an Out of Memory[
^],
Memory management in MDI forms[
^].
We don't really know what kind of memory leak you have, and, frankly, I don't sure if you have a leak at all or not. The actual detection of the leak is no so simple, and you should not trust not only Task Manager, but even the Performance Counter. Chances are, you would need a
memory debugger. Please see the article and the list of the memory debuggers:
http://en.wikipedia.org/wiki/Memory_debugger[
^].
Please see this Microsoft article on debugging, including memory issues:
http://msdn.microsoft.com/en-us/library/ee817660.aspx[
^].
Please see also this CodeProject article:
Get Started: Debugging Memory Related Issues in .Net Application Using WinDBG and SOS[
^].
[EDIT]
In WPF windows and controls, there is no a special need to use disposal at all.
Garbage collection copes with the managed memory by itself. You don't need to use
GC
class at all; and I recommend not touching it, ever (well, as a rule of thumb). Memory is reclaimed automatically. If is driven by making references
unreachable. This is well explained here:
http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29[
^].
As you cannot predict order of calling of your destructors, the destructors are also relatively rare in .NET programming.
And
IDisposable.Dispose
is still useful, but you can use it more with the
using
statement:
http://msdn.microsoft.com/en-us/library/yh598w02%28v=vs.80%29.aspx[
^].
For an interesting example, please see my articles:
Using "using" Statements: DisposalAccumulator[
^],
Hourglass Mouse Cursor Always Changes Back to its Original Image. How?[
^].
It's good to implement
RAII:
http://en.wikipedia.org/wiki/RAII[
^].
Please see this alternative:
Hourglass Mouse Cursor Always Changes Back to its Original Image. How?[
^].
—SA