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.
[quoted text, click to view] "Ben Voigt" wrote:
>
> "Scythen" <Scythen@discussions.microsoft.com> wrote in message
> news:77DB40C6-E9D3-499E-B4E8-60EB44740E40@microsoft.com...
> >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
> > of
> > my managed objects hold unmanaged interfaces provided by the application.
> > Some of these interfaces are unmanaged D3D interfaces.
> >
> > The system requires a specific startup and shutdown processes. In
> > particular
> > I need to ensure all of the managed objects are released in the Shutdown
> > function.
> >
> > In Shutdown I delete (or set to null) all references to managed objects
> > and
> > then force a garbage collection (and wait for it to finish). Unfortunately
> > some managed objects have survived and live on! What's worse is that some
> > of
> > 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?
>
>
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
[quoted text, click to view] Ben Voigt wrote:
> "Scythen" <Scythen@discussions.microsoft.com> wrote in message
> news:9419F820-0700-400B-A46B-759FE6E00CF5@microsoft.com...
> >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.
Don't see what you're looking for? Try a search.