I have a problem with mem allocate in c/c++ dll and call it with delphi, sth like this:
create a dll with c/c++
#include "MemTestDll.h"
extern "C" EXPORTAPI char* __cdecl Test()
{
char* str=new char[1024*1024*2];
return str;
}
then in delphi:
function Test():PAnsiChar; cdecl; external 'MemTestDll.dll';
procedure TForm3.btn3Click(Sender: TObject);
var
ptr:PAnsiChar;
begin
ptr:=Test();
//FreeMem(ptr); // crash
//SysFreeMem(ptr) //crash too
end;
I see the taskmanager,each click will leak 8 KB memory.
How can i release ptr? FreeMem this pointer will crash the application
I allocate 1024*1024*2 bytes in C/C++ dll,why it shows leak 8KB?