When working with the immediate window, one has to differ between runtime and designtime.
If I use the immediate Window on design time and put a local variable in stack:
string s = "test";
VS will start the compiler and create a new variable called s on the Heap and place a Pointer to it on a temporary stackframe it uses during designtime. (At least I think thats how it works, at least simplified. Please correct me if I'm wrong, though)
From now on, I am not able to use s for anything else, until I run my application or close VS:
int s = 12;
A local variable named 's' is already defined in this scope
I can use the contextmenu to clear the immediate window, but this really just clears the window itself. My local variables still stay on the stack.
I was wondering, if there is really not way to clear all variables I previously created inside the immediate window?
(Im using VS 2012 SP1 Prof. but I guess the issue stays the same with every version of VS)
I don't know the exact underpinnings of exactly what happens in visual studio, but it appears that VS keeps a compiled version in a vshost.exe process.
If you kill the associated process (i.e. WindowsFormsApplication1.vshost.exe *32), it will clear the stack and allow you to reuse the variable without having to restart VS.
Design-time debugging is described in this MSDN page. It is rather short on specific help that would address your issue. The example of Visual Basic code is not entirely by accident, this was an important feature in the VB6 IDE of old. And certainly more practical in that programming environment since it was common to write procedural code that was easy to test and debug with the Immediate window.
The quickest way I can think of clearing the execution state of the interpreter is to press F11 (Debug + Step Into) and cancel debugging. Or typing >Debug.StepInto and >Debug.StopDebugging. Not ideal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With