Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear Stack in Visual Studio Immediate Window

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)

like image 431
buddybubble Avatar asked Jan 03 '13 19:01

buddybubble


2 Answers

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.

like image 151
competent_tech Avatar answered Oct 15 '22 17:10

competent_tech


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.

like image 42
Hans Passant Avatar answered Oct 15 '22 16:10

Hans Passant