I'm hoping I can find someone here that can answer this:
Let's say I have a DLL written in C which has the following functions:
Now when I call this function using C#:Code:void get_string(char **pszStr) { char *s = malloc(32); strcpy(s,"Hello there"); *pszStr = s; } void free_string(char *pszStr) { free(pszStr); }
Is it necessary to call free_string() here? In C# memory management of the string class is taken care of by the implementation, but in the C dll the memory must be explicity released. I'm a little worried that free_string() won't actually work on the C# string, and therefore this is actually leaking memory.Code:[DllImport("cdll.dll")] unsafe static extern void get_string(out string str); [DllImport("cdll.dll")] unsafe static extern void free_string(string str); public void someMethod() { string str; get_string(out str); free_string(str); // <- is this necessary? }



LinkBack URL
About LinkBacks


