Hi,
This is related to how C++ new
works and how C++ object works.
Unlike C, C++ objects have constructors. The constructor is called when initializing the object to setup required values for the object to operate properly. With new
, it allocates the required memory and calls the constructor to setup the TString. But with malloc
it just allocate memory and does not initialize the object; leaving an empty shell of the object behind. When you use the empty shell - it crashes.