Sign in to follow this  

[.net] Garbage Collection between a DLL?

This topic is 4733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this