Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I don't know if "In-Memory debugger" is really what I mean, or if it's even possible to produce, but it's the best name I could come up with... Here's the tool I'm looking for:

  • Given a variable name, resolve that name to a reference
  • Given that reference, be able to watch the object referenced
  • Given the watch, be able to visualise it in a useful way, e.g.
    • browse the properties of the object as you can in Visual Studio
    • be notified when the object referenced is changed.

Here's a use case for this hypothetical tool. I have spent all of today trying to track down an ObjectDisposedException in my C# web app. The object being disposed is the WindowsIdentity of the current user, and there would appear to be a race condition causing the WindowsIdentity to be disposed before it is used. If I could watch a particular memory reference in an intelligent way, rather than a variable in some given scope, I think it would help me pin down the source of this sort of bug more easily.

Does such a tool exist for .NET?

share|improve this question
add comment

2 Answers

I think all you're asking for is already implemented in Visual Studio....

Could you explain what you couldn't achieve using VS debugger?

share|improve this answer
    
I haven't been able to work out how to do this in VS. If I add a watch, it's only valid for the scope in which the variable is defined. (If I pass something into a method as a parameter, and set a watch on that parameter, the watch is only valid for the parameter.) I want to be able to watch the value throughout its lifetime so I can see at what point it gets disposed. –  alastairs Nov 23 '10 at 0:05
    
What do you mean by 'get's disposed'? IDisposable.Dispose() called? Variable going out of scope? Object being garbage-collected? You can always see the value of the variable by navigating to the thread / frame where this variable lives. Watching the value of the variable won't help you in finding where the variable 'get's disposed' as this is probably not related to the value of variable being changed. - It looks like you have a different problem than the one described in your question that you want to solve. Ask about THAT instead. –  Jakub Konecki Nov 23 '10 at 6:32
add comment

If I understand correctly you want to know when a reference is changed. Well, just add a break point on the lines where the reference might be changed and you will break the execution when this happens (or before, depending on where you put the breakpoint).

About seeing variables in other contexts: you can see any variable as long as it exists in one context. Use the threads drop down to select different threads and the call stack to navigate between different frames.

share|improve this answer
    
I'll give this a go, thanks for the suggestions. I'm not sure, though, whether the reference is disposed in my own code, automatically through GC (perhaps as a result of an action of my code), or just as a result of one of the spun-off threads dying. –  alastairs Nov 23 '10 at 0:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.