Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / October 2006

Tip: Looking for answers? Try searching our database.

Is there a way to find what objects are referencing another object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Scythen - 25 Oct 2006 16:49 GMT
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.

How can I track down what is referencing these objects?
How can I ensure all of the managed objects get deleted?
Ben Voigt - 25 Oct 2006 19:08 GMT
>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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.