Alex Rivera | Logout

Find references to the object in runtime

Asked 2009-09-24T14:07:48.763
24

I have an object, which lives forever. I am deleteing all references I can see, to it after using it, but it still not collected. Its life cycle is pretty sophisticated so I can't be sure that all references been cleared.

if ( container.Controls.Count > 0 )
{ 
    var controls = new Control[ container.Controls.Count ];
    container.Controls.CopyTo( controls, 0 );

    foreach ( var control in controls ) 
    { 
         container.Controls.Remove( control );
         control.Dispose();
    }

    controls = null; 
}

GC.Collect();
GC.Collect(1);
GC.Collect(2);
GC.Collect(3);

How can I find out what references does it still have? Why is it not collected?

Edit
Report

1 Answer

0

It is not collected because you haven't removed all references to it. The GC will only mark objects for collection if they have no roots in the application.

What means are you using to check up on the GC to see if it has collected your object?

answered 2009-09-24T14:10:28.663

Your Answer