如果我使用 Marshal::StringToHGlobalAnsi
如下:
char *src = (char *)Marshal::StringToHGlobalAnsi(this->Textbox1->Text).ToPointer();
我需要使用 Marshal::FreeHGlobal()
吗?如果,我应该给什么参数?
最佳答案
根据 MSDN - 是的,您需要调用 FreeHGlobal。 http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.stringtohglobalansi%28v=VS.100%29.aspx :
Because this method allocates the unmanaged memory required for a string, always free the memory by calling FreeHGlobal
关于visual-c++ - 什么时候需要使用FreeHGlobal()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7692560/