Jump to content

Thomas B

Members
  • Content Count

    3
  • Joined

  • Last visited

Community Reputation

1 Neutral
  1. Thomas B

    Memory Leak when loading/unloading Delphi DLL

    Thank you, I didn't know that existed. I will create a bug report and link it here when done. Yes I just recreated the same behaviour with the host application written in Delphi. Here is the full code: program app; {$APPTYPE CONSOLE} uses Winapi.Windows; var lib: HMODULE; res: Boolean; begin while True do begin lib := LoadLibraryA('lib.dll'); if lib = 0 then begin WriteLn('LoadLibraryA failed'); Exit; end; res := FreeLibrary(lib); if res = False then begin WriteLn('FreeLibrary failed'); Exit; end; lib := 0; end; end.
  2. Thomas B

    Memory Leak when loading/unloading Delphi DLL

    I did not only use Task Manager, I also used the built-in memory profiler in Visual Studio. I know that Windows keeps around some memory. I did the same test with a DLL written in C/C++ and the memory usage grows up to around ~300KB then further LoadLibrary/FreeLibrary calls seem to reuse previous memory and the overall memory usage does not continue to grow. But that is not the case for the Delphi DLL. After running it for half an hour or so, the memory usage was already at a few houndred MB and it showed no sign of stopping. I tried using FastMM (ReportMemoryLeaksOnShutdown), but it did not show any leaks. Visual Studio memory profiler shows the allocations for each call but it only hints at "external code" and some memory address. According to the memory snapshots there are around ~5KB of memory allocations for each LoadLibrary call, that are not freed with FreeLibrary. All I can say for sure is that if I remove "uses System.SysUtils" the problem is gone, which is obviously not a fix, since I want to use some of the functionality.
  3. I have a weird problem with a memory leak caused by a DLL written in Delphi. As a test I have a C++ application that loads and unloads the DLL in a loop: HINSTANCE lib; while(1) { lib = LoadLibraryA("MyLib.dll"); FreeLibrary(lib); } When I look at the memory usage either in Task Manager or Visual Studio Memory Diagnostics, I can see that memory usage keeps growing indefinitely. Originally I thought it was caused by a leak in my Delphi code. But eventually I reduced it to: library MyLib; uses System.SysUtils; end. And the memory leak still appears. Only if I remove "uses System.SysUtils;" the leak is gone. I have tried to compile the DLL with Delphi XE2 and Delphi 11. The behaviour is the same. Does anyone know what causes this? Is there anything I can do (maybe some compiler settings?) to avoid the memory leak?
×