Freeing Memory Allocated By Unmanaged Dlll

  • Thread starter tristan.chaplin
  • Start date
T

tristan.chaplin

I have an unmanaged dll that returns a pointer (that it allocates, I
didn't allocate it with Marshal.AllocHGlobal), how do I free the memory
when I'm finished with it? It doesn't seem to like me calling
Marshal.FreeHGlobal on it.

I have heard rumours that the dll needs to supply its own destructor
function - is that true?
 
M

Mattias Sjögren

I have heard rumours that the dll needs to supply its own destructor
function - is that true?

It depends on which memory allocation API it uses. You have to find
that out first, hopefully the documentation will say.


Mattias
 
V

V

Hi,

If the Dll is something that you have written, then you need to
implement a method which allows freeing up memory from within the Dll
itself. You can then use this method to free the memory.

I don't think you would be allowed to free the memory allocated by the
dll from within your code.

Regards,
Vaibhav
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top