Memory Leak Using Delphi / DBExpress

I have a strange problem with my application, its memory usage is simultaneously increasing by several hundred megabytes, and in the end the application freezes. The application is written using Delphi, it uses a database, COM (for OPC) and TCP / IP.

With FastMM, I have a screen shot of memory usage. I'm not quite sure how to read this table, but it looks like something allocated 296463552 bytes (0x100fb000, is this a "magic number"?) Three times.

memory usage

Any ideas? Is there a way to track memory allocations other than Delphi-MM?

I am using Delphi 2007 with FastMM 4.96.

Edit:

I wrote a small helper class using IMallocSpy to track memory allocation in memory. Here is an excerpt from what I got:

00119023 5:52:27.484 [4496] TCOMAllocSpy.PreRealloc size: 269462304 00119024 5:52:27.734 [4496] (0002760C){ntdll.dll } [7C82860C] KiFastSystemCallRet + $0 00119025 5:52:27.734 [4496] (0009F83A){MyApp.exe} [004A083A] JclDebug.JclCreateThreadStackTrace (Line 3943, "JclDebug.pas" + 7) + $1E 00119026 5:52:27.734 [4496] (003D496A){MyApp.exe} [007D596A] ComLeakHelper.TCOMAllocSpy.DebugStack (Line 46, "ComLeakHelper.pas" + 2) + $9 00119027 5:52:27.734 [4496] (003D4B52){MyApp.exe} [007D5B52] ComLeakHelper.TCOMAllocSpy.PreRealloc (Line 125, "ComLeakHelper.pas" + 4) + $2 00119028 5:52:27.734 [4496] (000053B6){MyApp.exe} [004063B6] System.@WStrAsg (Line 14090, "sys\system.pas" + 10) + $0 00119029 5:52:27.734 [4496] (002E4490){MyApp.exe} [006E5490] DBXCommon.TDBXCommand.SetText (Line 5304, "..\..\..\..\..\src\pas\dbx\driver\DBXCommon.pas" + 13) + $5 00119030 5:52:27.734 [4496] (0010A340){MyApp.exe} [0050B340] WideStrings.TWideStrings.GetValue (Line 580, "common\WideStrings.pas" + 3) + $D 00119031 5:52:27.734 [4496] (002E1AFC){MyApp.exe} [006E2AFC] DBXCommon.TDBXProperties.GetValue (Line 4046, "..\..\..\..\..\src\pas\dbx\driver\DBXCommon.pas" + 1) + $7 00119032 5:52:27.734 [4496] (002E3FC9){MyApp.exe} [006E4FC9] DBXCommon.TDBXConnectionEx.GetProductName (Line 5071, "..\..\..\..\..\src\pas\dbx\driver\DBXCommon.pas" + 1) + $E 00119033 5:52:27.734 [4496] (003765FA){MyApp.exe} [007775FA] SqlExpr.TSQLConnection.DoConnect (Line 2467, "..\..\..\..\..\src\pas\dbx\vcl\SqlExpr.pas" + 66) + $21 00119034 5:52:27.734 [4496] (0011876D){MyApp.exe} [0051976D] DB.TCustomConnection.SetConnected (Line 2628, "DB.pas" + 8) + $4 00119035 5:52:27.734 [4496] (00118728){MyApp.exe} [00519728] DB.TCustomConnection.Open (Line 2611, "DB.pas" + 0) + $4 00119036 5:52:27.734 [4496] (00375D6F){MyApp.exe} [00776D6F] SqlExpr.TSQLConnection.CheckConnection (Line 2302, "..\..\..\..\..\src\pas\dbx\vcl\SqlExpr.pas" + 4) + $2 00119037 5:52:27.734 [4496] (00379241){MyApp.exe} [0077A241] SqlExpr.TCustomSQLDataSet.CheckConnection (Line 3955, "..\..\..\..\..\src\pas\dbx\vcl\SqlExpr.pas" + 2) + $2 00119038 5:52:27.734 [4496] (0037968A){MyApp.exe} [0077A68A] SqlExpr.TCustomSQLDataSet.OpenCursor (Line 4045, "..\..\..\..\..\src\pas\dbx\vcl\SqlExpr.pas" + 3) + $4 00119039 5:52:27.734 [4496] (00125EA9){MyApp.exe} [00526EA9] DB.TDataSet.SetActive (Line 9245, "DB.pas" + 12) + $7 00119040 5:52:27.734 [4496] (00125CA1){MyApp.exe} [00526CA1] DB.TDataSet.Open (Line 9201, "DB.pas" + 1) + $6 ... 

So the problem seems to be related to connecting to the database. I use Firebird 2.1, DBExpress and InterXpress for Firebird drivers from Upscene.

Edit2: It seems that the analysis of a similar problem, at least, focuses on the same areas as here: http://www.yac.com.pl/mt.texts.sqlexpr-2.en.html

+7
memory-management debugging memory-leaks delphi dbexpress
source share
3 answers

The problem is a bug in Delphi 2007 DbExpress, which runs in a multi-threaded environment (after all, it is not thread safe). Additional information here: http://www.yac.com.pl/mt.texts.sqlexpr-2.en.html

+2
source share

When your application is frozen, you can try looking at the stack to find out why it is frozen: http://code.google.com/p/asmprofiler/wiki/ProcessStackViewer

You can try memproof to track all resource allocations (and their stacktrace): http://www.torry.net/tools/debug/memory/memp0948.zip

+1
source share

Try EurekaLog to find the problem.

0
source share

All Articles