C # Free memory allocated by new operator from p / invoke DLL

I have a C # application that uses a third-party DLL (closed source) via p / invoke.

During some of these calls, the DLL allocates memory using the new / operator new [] operator and returns a pointer used to read the results.

This memory is never freed by the DLL after it is allocated and returned. How can I execute the equivalent of my own delete / operator delete [] operator in C #?

+3
source share
4 answers

. DLL , HeapCreate() . , , DLL. , DLL malloc .

, DLL, free(). DLL DLL- CRT, CRT, DLL CRT.

, GetProcessHeaps(). , , , . DLL, , , C ++. .NET, :)

+6

::operator new, P/Invoke ::operator delete, (, , DLL CRT). - AClass *p = new AClass, delete p P/Invoke, , ( - , new/). ++/CLI, , (, , , delete P/Invoke, , , ++/CLI, ).

+2

, , DLL Managed ++/CLI, .

0

I don't know if you can do this with unmanaged code, but a separate application domain may be the answer. Download it in your own memory space and simply delete the entire application domain when done.

0
source

Source: https://habr.com/ru/post/1762566/


All Articles