Was Dispose was called for the selected object?

flipdoubtflipdoubt Posts: 14
I am a new user comparing snapshots and looking at the Object Retention Graph for the object I am interested in. The graph just shows the object and the "No GC roots in current view" message. Unhiding the queue shows a bunch of objects, many of which have a tool tip saying "Dispose() has been called on this object." Here are my questions:

1. Hovering over selected object does not say whether Dispose was called. Was it? How can I tell?
2. The objects for which Dispose was called are gray and the current object is black. Does gray mean disposed and black mean not disposed? Is there a color that indicates an object that implements IDisposable but was not disposed?
3. The selected object has three GC root objects, all of which are "System.Windows.Forms.Control+ThreadMethodEntry args". I have never heard of that before. Any idea?
4. I don't fully get what the Finalizer Queue is. Can you point me to some good docs?

Comments

  • Hi there,

    you have sort of answered some of your own questions with points 1 & 2.

    When nothing initially appears in the Object Retention Graph except the object for which the graph was created for it's because Finalizer queue GC roots are keeping the object in memory and we hide these to begin with as they generally add lots of noise to the Object Retention Graph.

    The Finalizer queue objects should be removed when the next full Garbage Collection happens (i.e. when the next snapshot is taken) and the central object for which the graph was created will most likely be GC'd.

    - Anything which is grey has had Dispose called on it.
    - The black object is simply the object that you have created the graph for. Whether it has also had Dispose called - if you applied the Dispose filter from the panel and the object was still in the instance list and you created a graph from that object then it has had Dispose called.
    - Just because an object implements IDisposable doesn't mean that Dispose has ever actually been called. We do show objects that implement IDisposable and have been disposed - those are the grey objects mentioned above. We don't indicate objects on the graph that implement IDisposable but haven't had Dispose actually called yet.

    I think that the ThreadMethodEntry class is a particular implementation of IAsyncResult. You would typically create instances of this class when invoking asynchronous operations.

    I don't have any articles on the Finalizer queue but you might find this article helpful in understanding .NET memory management:
    http://www.simple-talk.com/dotnet/.net- ... n-in-.net/

    Regards,

    Stephen
  • Hi Stephen, thanks for the reference to that article. I will definitely take a good look at it.

    I still do not understand the answer to my question, about how to tell whether Dispose has been called on the selected object in the object retention graph. Since it says "Dispose() has been called for this object" for all objects in gray but not the object in black, am I too assume Dispose has not been called and the tool tip would contain the same message if Dispose had been called?

    As a suggestion for future versions, I think the graph itself should contain some indication as to whether Dispose has been called, rather than relegate that to tooltips not always displayed and not transferred to PDF or other export formats. For example, perhaps a garbage can icon with its lid on would indicate Dispose() was called (waiting for the "garbage man" to pick it up) and a garbage can with its lid open would indicate Dispose() was not called (waiting for the user to dispose of trash).
  • Hi,

    The only reason for the black object is because it's the central object. If you tooltip over it and it tells you Dispose() has been called that's also true. So it's a central object and had Dispose() called.

    I take your point about communicating this information via pdf exports to other people or when 2 dimensions conflict (i.e. central object and Dispose called) etc...

    We can definitely improve the visualisation of this in future versions - we actually do something similar in our performance profiler to indicate methods that are recursive so it's easy to do.

    I'll add it to the tracking system as a feature request for the next release.

    Thanks for posting.

    Stephen
  • Thanks. I am surprised because of the consistency with which Dispose has not been called on the object I select. I proved the tooltip should say "Dispose() has been called on this object" by showing the object retention graph for one of the parent objects that already had that message.

    Even in this version, I think the tooltip should say "Dispose has/has-not been called on this object" for the selected object. If the message is important enough to say about any IDisposable, I contend the inverse is important enough to say about the selected object.

    But my original suggestion of marking that for all IDisposables goes one step further.
Sign In or Register to comment.