One of the problems with statics is that you have no control over when they are instantiated as your program is loaded. In DEBUG mode, the compiler does many things differently than it does in RELEASE mode. One of those things is how it manages memory.
It is quite likely that you are simply getting lucky in DEBUG that your memory is not being overwritten by other processes and the value is there when your program wants it.
One approach I've used to great effect is a variation of the Meyers Singleton. (This is very nicely detailed in C++ In Theory: The Singleton Pattern - J. Nakamura
While you are not after a singleton, the approach can be used to solve your problem as follows:
class MySample
{
MySample() {}
<etc.>
static const std::string& GetStaticValue()
{
static std::string my_val = "Hello World";
return my_val;
}
}
The primary benefit is very nicely explained by Mr. Nakamura in the above article:
This construction relies on the fact that function-static objects are only initialized when the function is first being called upon; thus we maintain the benefit of dynamic initialization. (Function-static primitive variables like static int number=100; do get translated during compile time however!)