I have a medium sized Win32 application running 24/7 in heavy industry for more then a year. It has GUI and 2 communication threads, writing data to Oracle. Threads are updating GUI in thread safe way, and I have also implemented thread safe logging for main thread and communication threads. Application is usually running for months without stopping, and I do not have any memory leaks reported on application exit, as you can see in this heap trace output:
D:\Data\MyUserName\My Documents\Lazarus Projects\L1toOracle\L1toOracle.exe
Heap dump by heaptrc unit
277512 memory blocks allocated : 97836608/98786600
277512 memory blocks freed : 97836608/98786600
0 unfreed memory blocks : 0
True heap size : 327680
True free heap : 327536
Should be : 327680
The problem is that when I want to upgrade to any later FPC/Lazarus I get leaks as reported here (even if I just start application and exit it immediately):
d:\-\-\-\-\-\L1toOracle.exe
Heap dump by heaptrc unit
18330 memory blocks allocated : 2193384/2248376
18327 memory blocks freed : 2193316/2248296
3 unfreed memory blocks : 68
True heap size : 327680 (80 used in System startup)
True free heap : 327280
Should be : 327328
Call trace for block $00081170 size 28
$0070F4B6
$0070E2C5
$004107E6
$BAADF00D
$BAADF00D
$BAADF00D
$BAADF00D
$BAADF00D
Call trace for block $0007B370 size 12
$0070E2C5
$004107E6
$BAADF00D
$BAADF00D
$BAADF00D
$BAADF00D
$BAADF00D
$BAADF00D
Call trace for block $00081100 size 28
$006E1D1C
$004107E6
$004107E6
$BAADF00D
$BAADF00D
$BAADF00D
$BAADF00D
$BAADF00D
Compiling Lazarus with full debug info and running backtrace does not show anything useful, as you can see here:
GNU gdb (GDB) 7.9
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
This binary was built by Equation Solution <http://www.Equation.com>...
Reading symbols from L1toOracle.exe...done.
(gdb) run
Starting program: d:\-\-\-\-\-\L1toOracle.exe
[New Thread 7780.0x1778]
[New Thread 7780.0x10d4]
[Thread 7780.0x10d4 exited with code 0]
[New Thread 7780.0x136c]
[New Thread 7780.0x1aac]
[New Thread 7780.0x1670]
[New Thread 7780.0x210]
[Thread 7780.0x136c exited with code 0]
[Thread 7780.0x1aac exited with code 0]
[Thread 7780.0x1670 exited with code 0]
[Thread 7780.0x210 exited with code 0]
[Inferior 1 (process 7780) exited normally]
(gdb) bt
No stack.
(gdb)
In earlier cases when leaks were detected it was mostly my fault that could be located because line numbers and name hints were giving me enough info to get an idea where things went wrong. But this time I have no hints and I do not know where to look. I expected to get more info when I rebuilt Lazarus with "Debug IDE" profile ("-gw -gl -godwarfsets -gh -gt -Co -Cr -Ci -Sa"), but that was not the case. Did I make some error in this step?
I would really appreciate any idea or shared experience of the best strategy to start hunting this kind of leaks. Btw, project was initially done in CodeTyphon 5.60 and I faced the problem when trying to make it a Lazarus project. I have tried latest Lazarus stable, Lazarus trunk, and both Lazarus and FPC trunk, and leaks were always present (trunk was from about a month ago). I have also tried to update CodeTyphon and that was only partially successful. The latest CT version where I do not have any leaks is 5.80 (with all updates installed it reports FPC 3.1.1 SVN 51943 and Lazarus from 2016-04-02). Any later CT version also introduces leaks in my application.