[.net] Garbage Collection between a DLL?

Started by
0 comments, last by turnpast 19 years, 3 months ago
I am calling functions in an unmanaged DLL from C#. If my function returns a string will c# garbage collect on it when it is done? And if it does, how can I make it not? Add the unsafe keyword? -Greg
Advertisement
I think that it depends on how the string is returned. If the function returns a pointer to momory alocated within the legacy DLL than I believe that it is the DLL's responsibity to free it. If you pass a pointer to managed memory using the fixed statement that the DLL then fills the GC should collect it after the end of the fixed block and after you are done with it. Could be entirely wrong here so anyone else should feel free to correct me.

Here is a link to a part of the docs that kinda talks about this.

hope this helps.

This topic is closed to new replies.

Advertisement