What could explain that the instance of 'MyControl' is not garbage collected even though !dumpheap shows that there is no longer any strong reference to it
To put this in evidence I inserted a loop calling GC.Collect and a breakpoint at which I'm running !dumpheap.
What is even stranger to me is that 'MyControl' gets eventually collected, but later (after exiting Main).
This is annoying since 'MyControl' holds unmanaged memory and I'd like to check that I have no unmanaged memory leaks. This very late garbage collection causes inevitably false detections.
Chris.
------
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyFirstForm());
for (int n = 0; n < 100; n++)
{
GC.Collect();
GC.WaitForPendingFinalizers(); // <- breakpoint here
}
}
DOMAIN(005E1648):HANDLE(WeakLn):a1054:Root:028a620c(System.Windows.Forms.NativeMethods+WndProc)->
028a6100(System.Windows.Forms.Control+ControlNativeWindow)->
028a602c(MyNamespace.MyControl)->
028a5e78(System.Windows.Forms.TableLayoutPanel)->
028a5f2c(System.Windows.Forms.PropertyStore)->
028b3798(System.Windows.Forms.PropertyStore+ObjectEntry[])->
028aaaa4(System.Windows.Forms.Layout.TableLayout+ContainerInfo)->
028b3724(System.Object[])->
028aabcc(System.Windows.Forms.Layout.TableLayout+LayoutInfo)->
028a6344(System.Windows.Forms.TableLayoutPanel)->
028a63f8(System.Windows.Forms.PropertyStore)->
028b38ec(System.Windows.Forms.PropertyStore+ObjectEntry[])->
028aaf08(System.Windows.Forms.Layout.TableLayout+ContainerInfo)->
028b3850(System.Object[])->
028ab074(System.Windows.Forms.Layout.TableLayout+LayoutInfo)->
028a7918(System.Windows.Forms.GroupBox)->
028a798c(System.Windows.Forms.PropertyStore)->
028b2d40(System.Windows.Forms.PropertyStore+ObjectEntry[])->
028aba5c(System.Windows.Forms.Control+ControlCollection)->
028aba70(System.Collections.ArrayList)->
028aba88(System.Object[])->
028a7a28(System.Windows.Forms.TrackBar)->
028abaa8(System.ComponentModel.EventHandlerList)->
028abafc(System.ComponentModel.EventHandlerList+ListEntry)->
028abab8(System.EventHandler)->
028a5074(MyApp.MySecondForm)->
02896354(MyApp.MyFirstForm)->
02898d38(MyNamespace.MyControl)
DOMAIN(005E1648):HANDLE(WeakLn):a105c:Root:0289f590(System.Windows.Forms.NativeMethods+WndProc)->
02899e18(System.Windows.Forms.Control+ControlNativeWindow)->
02899d48(System.Windows.Forms.Button)->
0289a960(System.ComponentModel.EventHandlerList)->
0289b14c(System.ComponentModel.EventHandlerList+ListEntry)->
0289b12c(System.EventHandler)->
02896354(MyApp.MyFirstForm)
DOMAIN(005E1648):HANDLE(WeakLn):a1060:Root:0289f570(System.Windows.Forms.NativeMethods+WndProc)->
02899ccc(System.Windows.Forms.Control+ControlNativeWindow)->
02899bfc(System.Windows.Forms.Button)->
0289a92c(System.ComponentModel.EventHandlerList)->
0289b0e0(System.ComponentModel.EventHandlerList+ListEntry)->
0289b0c0(System.EventHandler)->
02896354(MyApp.MyFirstForm)
DOMAIN(005E1648):HANDLE(WeakLn):a107c:Root:0289f348(System.Windows.Forms.NativeMethods+WndProc)->
02897e34(System.Windows.Forms.Control+ControlNativeWindow)->
02897d64(System.Windows.Forms.Button)->
0289ab04(System.ComponentModel.EventHandlerList)->
0289acf8(System.ComponentModel.EventHandlerList+ListEntry)->
0289acd8(System.EventHandler)->
02896354(MyApp.MyFirstForm)
DOMAIN(005E1648):HANDLE(WeakLn):a108c:Root:0289f224(System.Windows.Forms.NativeMethods+WndProc)->
028979b0(System.Windows.Forms.Control+ControlNativeWindow)->
028978ec(System.Windows.Forms.TableLayoutPanel)->
028979a0(System.Windows.Forms.PropertyStore)->
0289f964(System.Windows.Forms.PropertyStore+ObjectEntry[])->
0289a844(System.Windows.Forms.Layout.TableLayout+ContainerInfo)->
0289f8c8(System.Object[])->
0289a908(System.Windows.Forms.Layout.TableLayout+LayoutInfo)->
02898d38(MyNamespace.MyControl)
DOMAIN(005E1648):HANDLE(WeakLn):a1098:Root:0289c888(System.Windows.Forms.NativeMethods+WndProc)->
02896554(System.Windows.Forms.Control+ControlNativeWindow)->
02896354(MyApp.MyFirstForm)
DOMAIN(005E1648):HANDLE(WeakLn):a10b4:Root:02899124(System.Windows.Forms.NativeMethods+WndProc)->
02898e0c(System.Windows.Forms.Control+ControlNativeWindow)->
02898d38(MyNamespace.MyControl)
DOMAIN(005E1648):HANDLE(WeakSh):a129c:Root:02898e0c(System.Windows.Forms.Control+ControlNativeWindow)
DOMAIN(005E1648):HANDLE(WeakSh):a12dc:Root:02896554(System.Windows.Forms.Control+ControlNativeWindow)