>I am writing a class library to be used with native C++ programs and I need
> to ensure all of the managed objects in the library have been freed. Some
[quoted text clipped - 14 lines]
> them are holding D3D resources that HAVE to be released before D3D is
> shutdown.
You need to implement IDisposable to deal with unmanaged resources and not
rely on the garbage collector.
> How can I track down what is referencing these objects?
> How can I ensure all of the managed objects get deleted?
Scythen - 30 Oct 2006 22:46 GMT
I do implement IDisposable.
The problem is not that unmanaged resources are not being cleaned up
correctly when they are garbage collected. The problem is that there are
managed objects that are still referenced by something after my shutdown
procedure. So, they are never garbage collected and Dispose is never called.
I’m sure I have left a reference to the objects somewhere that is causing
the problem but finding out where that reference is seems nearly impossible.
I did find one of the references; I had a static class member referencing
something that it shouldn’t have been. What I really need is a way to find
these references so I can remove them.
> >I am writing a class library to be used with native C++ programs and I need
> > to ensure all of the managed objects in the library have been freed. Some
[quoted text clipped - 20 lines]
> > How can I track down what is referencing these objects?
> > How can I ensure all of the managed objects get deleted?
Ben Voigt - 30 Oct 2006 23:53 GMT
>I do implement IDisposable.
> The problem is not that unmanaged resources are not being cleaned up
> correctly when they are garbage collected. The problem is that there are
> managed objects that are still referenced by something after my shutdown
> procedure. So, they are never garbage collected and Dispose is never
> called.
The garbage collector calls the finalizer, not Dispose. You should call
Dispose yourself when you are finished using the object.
Loy - 31 Oct 2006 10:37 GMT
Hi Scythen
You should use sos.dll debugger extension
Break after you request shutdown
Find the "leaking" object by !sos.dumpheap -type <your type here>
-cache
find one of the references to the object by: !sos.gcroot <your object
address>
Hope it helps
Loy
> >I do implement IDisposable.
> > The problem is not that unmanaged resources are not being cleaned up
[quoted text clipped - 5 lines]
> The garbage collector calls the finalizer, not Dispose. You should call
> Dispose yourself when you are finished using the object.