Well what's happening is that every time I "print" something, the C++ code waits a moment so that the page has a chance to render the new output. The click of the run button happens during that wait time, so if I start the new run immediately it reuses the same chunk of memory the old one was using. Once I hit the stop button, the destructors race and usually one ends up trying to access memory that's already freed.
If I add a delay in the run button, I'm giving the previous run a chance to run its destructors.