Possible Memory Leak with Pooling and Firebird (7.5.13)

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
FredS
Posts: 272
Joined: Mon 10 Nov 2014 17:52

Possible Memory Leak with Pooling and Firebird (7.5.13)

Post by FredS » Mon 24 Jun 2019 19:40

A quick test with Pooling enabled In Rio gave me this:

Code: Select all

allocation number: 766989
program up time: 20.52 s
type: GetMem
address: $168455b8
size: 16
access rights: read/write

thread $848:
671ee99f madExcept64.dll      madExceptDbg     1736 GetMemCallback
0040938e App.exe System                @GetMem
0269bfc6 App.exe IBCCallUni            TGDS.RegisterNotification
026b5ebf App.exe IBCClassesUni         TGDSConnection.InitGDS
026b860a App.exe IBCClassesUni         TGDSConnection.Connect
02374b59 App.exe CRConnectionPool      TCRLocalConnectionPool.OpenConnector
0237450d App.exe CRConnectionPool      TCRLocalConnectionPool.GetConnection
02375475 App.exe CRConnectionPool      TCRConnectionPoolManager.InternalGetConnection
02375554 App.exe CRConnectionPool      TCRConnectionPoolManager.GetConnection
0232935e App.exe DBAccess              TCustomDAConnection.GetIConnection
02329025 App.exe DBAccess              TCustomDAConnection.CreateIConnection
023c3b9a App.exe Uni                   TUniConnection.CreateIConnection
02329ef9 App.exe DBAccess              TCustomDAConnection.DoConnect
023c3ee4 App.exe Uni                   TUniConnection.DoConnect
0232a641 App.exe DBAccess              TCustomDAConnection.PerformConnect
0232ecbd App.exe DBAccess              TCustomDAConnection.SetConnected
0232a560 App.exe DBAccess              TCustomDAConnection.Connect
02650af3 App.exe DFX.Uni.Dac       958 TUniConnection.TryConnect
02657331 App.exe DFX.Uni.Dac      1775 TUniConnection.TryConnect
026513a1 App.exe DFX.Uni.Dac      1045 TUniConnection.ExecProcAsync$ActRec.$0$Body
005d9e4f App.exe System.Classes        TAnonymousThread.Execute
005057e4 App.exe madExcept             HookedTThreadExecute
005dc2f0 App.exe System.Classes        ThreadProc
004123da App.exe System                ThreadWrapper
005056b9 App.exe madExcept             ThreadExceptFrame
777e556b kernel32.dll                  BaseThreadInitThunk
77a4385b ntdll.dll                     RtlUserThreadStart
Running that without Pooling was fine, that was on my laptop without source. Might be able to get more detail tomorrow (with source).

FredS
Posts: 272
Joined: Mon 10 Nov 2014 17:52

Re: Possible Memory Leak with Pooling and Firebird (7.5.13)

Post by FredS » Mon 24 Jun 2019 21:55

Also in MSSQL, and in that I was able to use Pooling in 7.4.12.

Code: Select all

allocation number: 700341
program up time: 8.49 s
type: GetMem
address: $14b082a8
size: 16
access rights: read/write

thread $590:
671ee99f madExcept64.dll      madExceptDbg     1736 GetMemCallback
004094ef App.exe System                @GetMem
0265ea50 App.exe IBCCallUni       3698 TGDS.RegisterNotification
0267a311 App.exe IBCClassesUni    1828 TGDSConnection.InitGDS
0267d01d App.exe IBCClassesUni    2181 TGDSConnection.Connect
02368d4a App.exe CRConnectionPool  551 TCRLocalConnectionPool.OpenConnector
02368616 App.exe CRConnectionPool  467 TCRLocalConnectionPool.GetConnection
02369832 App.exe CRConnectionPool  742 TCRConnectionPoolManager.InternalGetConnection
0236995a App.exe CRConnectionPool  772 TCRConnectionPoolManager.GetConnection
02313a9e App.exe DBAccess         3868 TCustomDAConnection.GetIConnection
0231366f App.exe DBAccess         3813 TCustomDAConnection.CreateIConnection
023beb0b App.exe Uni              1793 TUniConnection.CreateIConnection
02314869 App.exe DBAccess         4182 TCustomDAConnection.DoConnect
023bee64 App.exe Uni              1859 TUniConnection.DoConnect
02315061 App.exe DBAccess         4316 TCustomDAConnection.PerformConnect
02319d52 App.exe DBAccess         5378 TCustomDAConnection.SetConnected
02314f5a App.exe DBAccess         4293 TCustomDAConnection.Connect
02314db2 App.exe DBAccess         4263 TCustomDAConnection.InternalConnect
02324c74 App.exe DBAccess         7895 TCustomDADataSet.BeginConnection
023c4019 App.exe Uni              3249 TCustomUniDataSet.BeginConnection
02326689 App.exe DBAccess         8294 TCustomDADataSet.OpenCursor
023c433d App.exe Uni              3329 TCustomUniDataSet.OpenCursor
00973ea0 App.exe Data.DB               TDataSet.SetActive
02326599 App.exe DBAccess         8271 TCustomDADataSet.SetActive
00973c40 App.exe Data.DB               TDataSet.Open
02619ffb App.exe DFX.Uni.Dac      1385 TUniQueryHelper.OpenAsync$50$ActRec.$0$Body
008fc48a App.exe System.Threading 2128 TTask.Execute
008fd94f App.exe System.Threading 2463 TTask.InternalExecute
008fdada App.exe System.Threading 2490 TTask.InternalWork
008fca58 App.exe System.Threading 2169 TTask.ExecuteWork
009012b7 App.exe System.Threading 3373 TThreadPool.TQueueWorkerThread.ExecuteWorkItem
00900da8 App.exe System.Threading 3315 TThreadPool.TQueueWorkerThread.Execute
00501fa4 App.exe madExcept             HookedTThreadExecute
005d4d40 App.exe System.Classes        ThreadProc
004122c8 App.exe System                ThreadWrapper
00501e79 App.exe madExcept             ThreadExceptFrame
7ff97a64 KERNEL32.DLL                               BaseThreadInitThunk
7ff97cea ntdll.dll                                  RtlUserThreadStart

memory dump: 
14b082a8  30 e8 67 02 00 00 00 00 - e8 6d 99 1a 00 00 00 00  0.g......m......

allocation number: 694289
program up time: 8.38 s
type: GetMem
address: $14a72da8
size: 16
access rights: read/write

thread $1830:
671ee99f madExcept64.dll      madExceptDbg     1736 GetMemCallback
004094ef App.exe System                @GetMem
0265ea50 App.exe IBCCallUni       3698 TGDS.RegisterNotification
0267a311 App.exe IBCClassesUni    1828 TGDSConnection.InitGDS
0267d01d App.exe IBCClassesUni    2181 TGDSConnection.Connect
02368d4a App.exe CRConnectionPool  551 TCRLocalConnectionPool.OpenConnector
02368616 App.exe CRConnectionPool  467 TCRLocalConnectionPool.GetConnection
02369832 App.exe CRConnectionPool  742 TCRConnectionPoolManager.InternalGetConnection
0236995a App.exe CRConnectionPool  772 TCRConnectionPoolManager.GetConnection
02313a9e App.exe DBAccess         3868 TCustomDAConnection.GetIConnection
0231366f App.exe DBAccess         3813 TCustomDAConnection.CreateIConnection
023beb0b App.exe Uni              1793 TUniConnection.CreateIConnection
02314869 App.exe DBAccess         4182 TCustomDAConnection.DoConnect
023bee64 App.exe Uni              1859 TUniConnection.DoConnect
02315061 App.exe DBAccess         4316 TCustomDAConnection.PerformConnect
02319d52 App.exe DBAccess         5378 TCustomDAConnection.SetConnected
02314f5a App.exe DBAccess         4293 TCustomDAConnection.Connect
02314db2 App.exe DBAccess         4263 TCustomDAConnection.InternalConnect
02324c74 App.exe DBAccess         7895 TCustomDADataSet.BeginConnection
023c4019 App.exe Uni              3249 TCustomUniDataSet.BeginConnection
02326689 App.exe DBAccess         8294 TCustomDADataSet.OpenCursor
023c433d App.exe Uni              3329 TCustomUniDataSet.OpenCursor
00973ea0 App.exe Data.DB               TDataSet.SetActive
02326599 App.exe DBAccess         8271 TCustomDADataSet.SetActive
00973c40 App.exe Data.DB               TDataSet.Open
02619ffb App.exe DFX.Uni.Dac      1385 TUniQueryHelper.OpenAsync$50$ActRec.$0$Body
008fc48a App.exe System.Threading 2128 TTask.Execute
008fd94f App.exe System.Threading 2463 TTask.InternalExecute
008fdada App.exe System.Threading 2490 TTask.InternalWork
008fca58 App.exe System.Threading 2169 TTask.ExecuteWork
009012b7 App.exe System.Threading 3373 TThreadPool.TQueueWorkerThread.ExecuteWorkItem
00900da8 App.exe System.Threading 3315 TThreadPool.TQueueWorkerThread.Execute
00501fa4 App.exe madExcept             HookedTThreadExecute
005d4d40 App.exe System.Classes        ThreadProc
004122c8 App.exe System                ThreadWrapper
00501e79 App.exe madExcept             ThreadExceptFrame
7ff97a64 KERNEL32.DLL                               BaseThreadInitThunk
7ff97cea ntdll.dll                                  RtlUserThreadStart

memory dump: 
14a72da8  30 e8 67 02 00 00 00 00 - d8 79 da 16 00 00 00 00  0.g......y......

allocation number: 688479
program up time: 8.08 s
type: GetMem
address: $14b0b188
size: 16
access rights: read/write

thread $ce4:
671ee99f madExcept64.dll      madExceptDbg     1736 GetMemCallback
004094ef App.exe System                @GetMem
0265ea50 App.exe IBCCallUni       3698 TGDS.RegisterNotification
0267a311 App.exe IBCClassesUni    1828 TGDSConnection.InitGDS
0267d01d App.exe IBCClassesUni    2181 TGDSConnection.Connect
02368d4a App.exe CRConnectionPool  551 TCRLocalConnectionPool.OpenConnector
02368616 App.exe CRConnectionPool  467 TCRLocalConnectionPool.GetConnection
02369832 App.exe CRConnectionPool  742 TCRConnectionPoolManager.InternalGetConnection
0236995a App.exe CRConnectionPool  772 TCRConnectionPoolManager.GetConnection
02313a9e App.exe DBAccess         3868 TCustomDAConnection.GetIConnection
0231366f App.exe DBAccess         3813 TCustomDAConnection.CreateIConnection
023beb0b App.exe Uni              1793 TUniConnection.CreateIConnection
02314869 App.exe DBAccess         4182 TCustomDAConnection.DoConnect
023bee64 App.exe Uni              1859 TUniConnection.DoConnect
02315061 App.exe DBAccess         4316 TCustomDAConnection.PerformConnect
02319d52 App.exe DBAccess         5378 TCustomDAConnection.SetConnected
02314f5a App.exe DBAccess         4293 TCustomDAConnection.Connect
02314db2 App.exe DBAccess         4263 TCustomDAConnection.InternalConnect
02324c74 App.exe DBAccess         7895 TCustomDADataSet.BeginConnection
023c4019 App.exe Uni              3249 TCustomUniDataSet.BeginConnection
02326689 App.exe DBAccess         8294 TCustomDADataSet.OpenCursor
023c433d App.exe Uni              3329 TCustomUniDataSet.OpenCursor
00973ea0 App.exe Data.DB               TDataSet.SetActive
02326599 App.exe DBAccess         8271 TCustomDADataSet.SetActive
00973c40 App.exe Data.DB               TDataSet.Open
02619ffb App.exe DFX.Uni.Dac      1385 TUniQueryHelper.OpenAsync$50$ActRec.$0$Body
008fc48a App.exe System.Threading 2128 TTask.Execute
008fd94f App.exe System.Threading 2463 TTask.InternalExecute
008fdada App.exe System.Threading 2490 TTask.InternalWork
008fca58 App.exe System.Threading 2169 TTask.ExecuteWork
009012b7 App.exe System.Threading 3373 TThreadPool.TQueueWorkerThread.ExecuteWorkItem
00900da8 App.exe System.Threading 3315 TThreadPool.TQueueWorkerThread.Execute
00501fa4 App.exe madExcept             HookedTThreadExecute
005d4d40 App.exe System.Classes        ThreadProc
004122c8 App.exe System                ThreadWrapper
00501e79 App.exe madExcept             ThreadExceptFrame
7ff97a64 KERNEL32.DLL                               BaseThreadInitThunk
7ff97cea ntdll.dll                                  RtlUserThreadStart

memory dump: 
14b0b188  30 e8 67 02 00 00 00 00 - f8 6e bb 1a 00 00 00 00  0.g......n......

allocation number: 667082
program up time: 6.42 s
type: GetMem
address: $14dc7b98
size: 16
access rights: read/write

main thread ($2b9c):
671ee99f madExcept64.dll      madExceptDbg     1736 GetMemCallback
004094ef App.exe System                @GetMem
0265ea50 App.exe IBCCallUni       3698 TGDS.RegisterNotification
0267a311 App.exe IBCClassesUni    1828 TGDSConnection.InitGDS
0267d01d App.exe IBCClassesUni    2181 TGDSConnection.Connect
02368d4a App.exe CRConnectionPool  551 TCRLocalConnectionPool.OpenConnector
02368616 App.exe CRConnectionPool  467 TCRLocalConnectionPool.GetConnection
02369832 App.exe CRConnectionPool  742 TCRConnectionPoolManager.InternalGetConnection
0236995a App.exe CRConnectionPool  772 TCRConnectionPoolManager.GetConnection
02313a9e App.exe DBAccess         3868 TCustomDAConnection.GetIConnection
0231366f App.exe DBAccess         3813 TCustomDAConnection.CreateIConnection
023beb0b App.exe Uni              1793 TUniConnection.CreateIConnection
02314869 App.exe DBAccess         4182 TCustomDAConnection.DoConnect
023bee64 App.exe Uni              1859 TUniConnection.DoConnect
02315061 App.exe DBAccess         4316 TCustomDAConnection.PerformConnect
02319d52 App.exe DBAccess         5378 TCustomDAConnection.SetConnected
02314f5a App.exe DBAccess         4293 TCustomDAConnection.Connect
02616993 App.exe DFX.Uni.Dac       958 TUniConnection.TryConnect
0261cdc1 App.exe DFX.Uni.Dac      1775 TUniConnection.TryConnect
0287ee20 App.exe DataDataMod      1239 TDataDM.OpenDatabase
028b2f72 App.exe MainFrm          1514 TMainForm.LoadDataBase
028b278c App.exe MainFrm          1478 TMainForm.AfterFirstShow
02603483 App.exe DFX.Form.Base     645 TDfxBaseForm.CMShowingChanged
0040f75e App.exe System                TObject.Dispatch
006ee1e3 App.exe Vcl.Controls          TControl.WndProc
006f5092 App.exe Vcl.Controls          TWinControl.WndProc
0080cf7b App.exe Vcl.Forms             TCustomForm.WndProc
00c0d981 App.exe cxControls            TcxWindowProcLinkedObject.DefaultProc
01e9d217 App.exe dxBar                 TdxBarManager.OwnerWindowProc
00c0d981 App.exe cxControls            TcxWindowProcLinkedObject.DefaultProc
0211dde3 App.exe dxUIAdorners          TdxBadges.OwnerWindowWndProc
00c0d981 App.exe cxControls            TcxWindowProcLinkedObject.DefaultProc
02118728 App.exe dxUIAdorners          TdxGuideLayeredWindow.OwnerWindowWndProc
00c0df31 App.exe cxControls            TcxWindowProcLinkedObjectList.WndProc
006edcc0 App.exe Vcl.Controls          TControl.Perform
006f3fd2 App.exe Vcl.Controls          TWinControl.UpdateShowing
006f4110 App.exe Vcl.Controls          TWinControl.UpdateControlState
006f83e0 App.exe Vcl.Controls          TWinControl.CMVisibleChanged
0040f75e App.exe System                TObject.Dispatch
006ee1e3 App.exe Vcl.Controls          TControl.WndProc
006f5092 App.exe Vcl.Controls          TWinControl.WndProc
0080cf7b App.exe Vcl.Forms             TCustomForm.WndProc
00c0d981 App.exe cxControls            TcxWindowProcLinkedObject.DefaultProc
01e9d217 App.exe dxBar                 TdxBarManager.OwnerWindowProc
00c0d981 App.exe cxControls            TcxWindowProcLinkedObject.DefaultProc
0211dde3 App.exe dxUIAdorners          TdxBadges.OwnerWindowWndProc
00c0d981 App.exe cxControls            TcxWindowProcLinkedObject.DefaultProc
02118728 App.exe dxUIAdorners          TdxGuideLayeredWindow.OwnerWindowWndProc
00c0df31 App.exe cxControls            TcxWindowProcLinkedObjectList.WndProc
006edcc0 App.exe Vcl.Controls          TControl.Perform
006ebad1 App.exe Vcl.Controls          TControl.SetVisible
0080c41a App.exe Vcl.Forms             TCustomForm.SetVisible
0081b525 App.exe Vcl.Forms             TApplication.Run
028ea657 App.exe App   65 initialization
7ff97a64 KERNEL32.DLL                               BaseThreadInitThunk
7ff97cea ntdll.dll                                  RtlUserThreadStart

memory dump: 
14dc7b98  30 e8 67 02 00 00 00 00 - 38 2d bc 13 00 00 00 00  0.g.....8-......

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Possible Memory Leak with Pooling and Firebird (7.5.13)

Post by ViktorV » Wed 26 Jun 2019 12:05

We haven't identified any memory leaks during testing. To further investigate the described behavior of UniDAC, we need a small sample demonstrating the behavior, including scripts for creating and filling database objects. Please compose a sample and send us via the contact form on our website: https://devart.com/company/contactform.html

FredS
Posts: 272
Joined: Mon 10 Nov 2014 17:52

Re: Possible Memory Leak with Pooling and Firebird (7.5.13)

Post by FredS » Wed 26 Jun 2019 15:05

ViktorV wrote: Wed 26 Jun 2019 12:05 We haven't identified any memory leaks during testing.
I did a bit more testing and can tell you that this doesn't appear to be a complex issue to reproduce:

- No leaks occur with Pooling Off
- Each (threaded) connection shows as a leak, 8 during a local test run
- With madExcept off I get this using: ReportMemoryLeaksOnShutdown := True;

---------------------------
Unexpected Memory Leak
---------------------------
An unexpected memory leak has occurred. The unexpected small block leaks are:

9 - 24 bytes: Unknown x 4

---------------------------
OK
---------------------------

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Possible Memory Leak with Pooling and Firebird (7.5.13)

Post by ViktorV » Mon 01 Jul 2019 13:08

Unfortunately, we cannot reproduce the issue using the information provided by you.
To understand the cause of the issue and find a solution to fix it, we need a test sample in which the issue is stably reproduced. As soon as we get such an sample and if the cause of the issue is in the code of our product, we will try to fix it as soon as possible.
Please, compose and send us using the contact form https://devart.com/company/contactform.html a small sample demonstrating the behavior, including scripts for creating and populating database objects. Also, specify steps to reproduce the issue.

FredS
Posts: 272
Joined: Mon 10 Nov 2014 17:52

Re: Memory Leak with Pooling

Post by FredS » Wed 03 Jul 2019 16:38

Here are call stack sections of what happens, not something reproducible in a trivial demo:

* IBCClassesUni.TGDSConnection.Destroy

Code: Select all

  if FGDS <> nil then << ********* Always NIL *********
    FGDS.UnRegisterNotification(GDSNotification); << ********* NEVER CALLED *********
* FGDS.UnRegisterNotification(GDSNotification);

Code: Select all

      pEvent := PNotificationRec(FNotifications[i]);
		  if pEvent.Data = TMethod(Event).Data then begin
			Dispose(PNotificationRec(FNotifications[i])); << ********* NEVER Disposed *********
			FNotifications.Delete(i);
			Break;
		  end;
System.TObject.Free
CRConnectionPool.TCRLocalConnectionPool.InternalFreeConnection($128C93B8,False)
CRConnectionPool.TCRLocalConnectionPool.Clear
CRConnectionPool.TCRLocalConnectionPool.Destroy
System.TObject.Free
CRTypes.TCRObjectList.Notify($16BB8B08,lnDeleted)
System.Classes.TList.SetCount(???)
System.Classes.TList.Clear
CRConnectionPool.TCRConnectionPoolManager.InternalClear
CRConnectionPool.TCRConnectionPoolManager.Destroy
System.TObject.Free
CRTypes.TCRObjectList.Notify($16C62348,lnDeleted)
System.Classes.TList.SetCount(0)
System.Classes.TList.Clear
System.Classes.TList.Destroy
System.TObject.Free
CRConnectionPool.ClearPoolManager
CRConnectionPool.Finalization
System.FinalizeUnits


IBCCallUni.TGDS.FreeGDS
*IBCClassesUni.TGDSConnection.GDSNotification

Code: Select all

  Disconnect;
  FGDS := nil; << ********* Set to Nil in each connection ********* 
*IBCCallUni.TGDS.Destroy

Code: Select all

  fires NotificationEvent; << ********* Calls GDSNotification for each connection *********
System.TObject.Free
IBCCallUni.TGDSList.Clear
IBCCallUni.TGDSList.Destroy
System.TObject.Free
IBCCallUni.Finalization
System.FinalizeUnits

Note: Changed the subject since it's reproducible in both MSSQL and FB3.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Possible Memory Leak with Pooling and Firebird (7.5.13)

Post by ViktorV » Thu 04 Jul 2019 05:16

Unfortunately, we cannot reproduce the problem in our environment based on the data you provide.
To understand the cause of the issue and find a solution to fix it, we need a test sample in which the issue is stably reproduced. As soon as we get such an sample and if the cause of the issue is in the code of our product, we will try to fix it as soon as possible.
Therefore, the only way to solve it, try to compile and send us using the contact form https://devart.com/company/contactform.html an example of a reproducing error, including scripts for creating and populating database objects.

FredS
Posts: 272
Joined: Mon 10 Nov 2014 17:52

Re: Possible Memory Leak with Pooling and Firebird (7.5.13)

Post by FredS » Thu 04 Jul 2019 21:07

Uses your Demo database, you may need to regenerate or update the RecID.

Code: Select all

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  System.Threading, Uni, InterBaseUniProvider;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure BecauseMemoryLeakCheckFailsinD10Console;
var
  LCon : TUniConnection;
  LTaskList : TArray<ITask>;
  i, x, RecID : integer;
  { CreateTask }
  function CreateTask(ATaskID, ARecID: Integer; ACon: TUniConnection): ITask; inline;
  begin
    Result := TTask.Create( procedure begin
       try
         ACon.Connect;
         ACon.ExecSQL('Insert into dept values(:RecID, :DName, :Loc)', [ARecID, 'from Task ' + ATaskID.ToString, 'PoolingDemo']);
         ACon.Disconnect;
       finally
         ACon.Free;
       end;
    end);
  end;
begin
  try
    LCon := TUniConnection.Create(nil);
    try
      LCon.Server       := <server>
      LCon.ProviderName := 'Interbase';
      LCon.Database     := 'demo.fdb';
      LCon.Username     := 'sysdba';
      LCon.Password     := 'masterkey';
      LCon.LoginPrompt  := False;
      LCon.Pooling      := True;
      LCon.PoolingOptions.MinPoolSize := 4;
      LCon.PoolingOptions.MaxPoolSize := 100;
      LCon.Connect;
      LCon.ExecSQL('Delete from dept where loc = :loc', ['PoolingDemo']);

      RecID := 40;
      Setlength(LTaskList, 10);
      for x := 1 to 10 do begin
        for i := 0 to 9 do begin
          inc(RecID);
          LTaskList[i] := CreateTask(i+1, RecID, TUniConnection.Create(nil, LCon.ConnectString));
        end;
        for i := 0 to 9 do LTaskList[i].Start;
        TTask.WaitForAll(LTaskList);
      end;

      LCon.Close;
    finally
      LCon.Free;
    end;
  except
    on E: Exception do
      ShowMessage(E.ClassName + ': ' + E.Message);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ReportMemoryLeaksOnShutdown := True;
  BecauseMemoryLeakCheckFailsinD10Console;
  PostMessage(handle, WM_QUIT, 0 , 0);
end;

end.
MadExcept Leak Report:

Code: Select all

allocation number: 57952
program up time: 4.82 s
type: GetMem
address: $88468c8
size: 8
access rights: read/write

thread $c8c (TThreadPool.TQueueWorkerThread):
671a536b madExcept32.dll    madExceptDbg      1736 GetMemCallback
007fa27a PoolingDemoVCL.exe IBCCallUni             TGDSList.FindGDS
00406f24 PoolingDemoVCL.exe System            4799 @GetMem
007fc8d3 PoolingDemoVCL.exe IBCCallUni             TGDS.RegisterNotification
0080e123 PoolingDemoVCL.exe IBCClassesUni          TGDSConnection.InitGDS
0080fe29 PoolingDemoVCL.exe IBCClassesUni          TGDSConnection.Connect
007c0c4b PoolingDemoVCL.exe CRConnectionPool       TCRLocalConnectionPool.OpenConnector
007c072d PoolingDemoVCL.exe CRConnectionPool       TCRLocalConnectionPool.GetConnection
007c12f1 PoolingDemoVCL.exe CRConnectionPool       TCRConnectionPoolManager.InternalGetConnection
007c13a1 PoolingDemoVCL.exe CRConnectionPool       TCRConnectionPoolManager.GetConnection
0078ec51 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.GetIConnection
007f1a09 PoolingDemoVCL.exe Uni                    TUniConnection.CheckProvider
0078ea2a PoolingDemoVCL.exe DBAccess               TCustomDAConnection.CreateIConnection
007f1d9e PoolingDemoVCL.exe Uni                    TUniConnection.CreateIConnection
0078f406 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.DoConnect
007f1fbf PoolingDemoVCL.exe Uni                    TUniConnection.DoConnect
0078f839 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.PerformConnect
007927f6 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.SetConnected
0078f7c4 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.Connect
0083350b PoolingDemoVCL.exe Unit1               30 CreateTask$ActRec.$0$Body
00685f85 PoolingDemoVCL.exe System.Threading  2055 TTask.Execute
00686cf5 PoolingDemoVCL.exe System.Threading  2390 TTask.InternalExecute
00686de9 PoolingDemoVCL.exe System.Threading  2417 TTask.InternalWork
0068ac69 PoolingDemoVCL.exe System.Threading  3341 TThreadPool.TQueueWorkerThread.ExecuteWorkItem
0068a8eb PoolingDemoVCL.exe System.Threading  3270 TThreadPool.TQueueWorkerThread.Execute
004acfdb PoolingDemoVCL.exe madExcept              HookedTThreadExecute
004ec3d9 PoolingDemoVCL.exe System.Classes   15048 ThreadProc
0040a72c PoolingDemoVCL.exe System           24940 ThreadWrapper
004acec1 PoolingDemoVCL.exe madExcept              CallThreadProcSafe
004acf26 PoolingDemoVCL.exe madExcept              ThreadExceptFrame
7536343b kernel32.dll                              BaseThreadInitThunk

memory dump: 
088468c8  f0 0e 81 00 88 9c c4 05                            ........

allocation number: 37831
program up time: 4.32 s
type: GetMem
address: $889c348
size: 8
access rights: read/write

thread $fcc (TThreadPool.TQueueWorkerThread):
671a536b madExcept32.dll    madExceptDbg      1736 GetMemCallback
007fa27a PoolingDemoVCL.exe IBCCallUni             TGDSList.FindGDS
00406f24 PoolingDemoVCL.exe System            4799 @GetMem
007fc8d3 PoolingDemoVCL.exe IBCCallUni             TGDS.RegisterNotification
0080e123 PoolingDemoVCL.exe IBCClassesUni          TGDSConnection.InitGDS
0080fe29 PoolingDemoVCL.exe IBCClassesUni          TGDSConnection.Connect
007c0c4b PoolingDemoVCL.exe CRConnectionPool       TCRLocalConnectionPool.OpenConnector
007c072d PoolingDemoVCL.exe CRConnectionPool       TCRLocalConnectionPool.GetConnection
007c12f1 PoolingDemoVCL.exe CRConnectionPool       TCRConnectionPoolManager.InternalGetConnection
007c13a1 PoolingDemoVCL.exe CRConnectionPool       TCRConnectionPoolManager.GetConnection
0078ec51 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.GetIConnection
007f1a09 PoolingDemoVCL.exe Uni                    TUniConnection.CheckProvider
0078ea2a PoolingDemoVCL.exe DBAccess               TCustomDAConnection.CreateIConnection
007f1d9e PoolingDemoVCL.exe Uni                    TUniConnection.CreateIConnection
0078f406 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.DoConnect
007f1fbf PoolingDemoVCL.exe Uni                    TUniConnection.DoConnect
0078f839 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.PerformConnect
007927f6 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.SetConnected
0078f7c4 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.Connect
0083350b PoolingDemoVCL.exe Unit1               30 CreateTask$ActRec.$0$Body
00685f85 PoolingDemoVCL.exe System.Threading  2055 TTask.Execute
00686cf5 PoolingDemoVCL.exe System.Threading  2390 TTask.InternalExecute
00686de9 PoolingDemoVCL.exe System.Threading  2417 TTask.InternalWork
0068ac69 PoolingDemoVCL.exe System.Threading  3341 TThreadPool.TQueueWorkerThread.ExecuteWorkItem
0068a8eb PoolingDemoVCL.exe System.Threading  3270 TThreadPool.TQueueWorkerThread.Execute
004acfdb PoolingDemoVCL.exe madExcept              HookedTThreadExecute
004ec3d9 PoolingDemoVCL.exe System.Classes   15048 ThreadProc
0040a72c PoolingDemoVCL.exe System           24940 ThreadWrapper
004acec1 PoolingDemoVCL.exe madExcept              CallThreadProcSafe
004acf26 PoolingDemoVCL.exe madExcept              ThreadExceptFrame
7536343b kernel32.dll                              BaseThreadInitThunk

memory dump: 
0889c348  f0 0e 81 00 48 8b c4 05                            ....H...

allocation number: 10156
program up time: 3.35 s
type: GetMem
address: $886ab38
size: 8
access rights: read/write

thread $118 (TThreadPool.TQueueWorkerThread):
671a536b madExcept32.dll    madExceptDbg      1736 GetMemCallback
007fa27a PoolingDemoVCL.exe IBCCallUni             TGDSList.FindGDS
00406f24 PoolingDemoVCL.exe System            4799 @GetMem
007fc8d3 PoolingDemoVCL.exe IBCCallUni             TGDS.RegisterNotification
0080e123 PoolingDemoVCL.exe IBCClassesUni          TGDSConnection.InitGDS
0080fe29 PoolingDemoVCL.exe IBCClassesUni          TGDSConnection.Connect
007c0c4b PoolingDemoVCL.exe CRConnectionPool       TCRLocalConnectionPool.OpenConnector
007c072d PoolingDemoVCL.exe CRConnectionPool       TCRLocalConnectionPool.GetConnection
007c12f1 PoolingDemoVCL.exe CRConnectionPool       TCRConnectionPoolManager.InternalGetConnection
007c13a1 PoolingDemoVCL.exe CRConnectionPool       TCRConnectionPoolManager.GetConnection
0078ec51 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.GetIConnection
007f1a09 PoolingDemoVCL.exe Uni                    TUniConnection.CheckProvider
0078ea2a PoolingDemoVCL.exe DBAccess               TCustomDAConnection.CreateIConnection
007f1d9e PoolingDemoVCL.exe Uni                    TUniConnection.CreateIConnection
0078f406 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.DoConnect
007f1fbf PoolingDemoVCL.exe Uni                    TUniConnection.DoConnect
0078f839 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.PerformConnect
007927f6 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.SetConnected
0078f7c4 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.Connect
0083350b PoolingDemoVCL.exe Unit1               30 CreateTask$ActRec.$0$Body
00685f85 PoolingDemoVCL.exe System.Threading  2055 TTask.Execute
00686cf5 PoolingDemoVCL.exe System.Threading  2390 TTask.InternalExecute
00686de9 PoolingDemoVCL.exe System.Threading  2417 TTask.InternalWork
0068ac69 PoolingDemoVCL.exe System.Threading  3341 TThreadPool.TQueueWorkerThread.ExecuteWorkItem
0068a8eb PoolingDemoVCL.exe System.Threading  3270 TThreadPool.TQueueWorkerThread.Execute
004acfdb PoolingDemoVCL.exe madExcept              HookedTThreadExecute
004ec3d9 PoolingDemoVCL.exe System.Classes   15048 ThreadProc
0040a72c PoolingDemoVCL.exe System           24940 ThreadWrapper
004acec1 PoolingDemoVCL.exe madExcept              CallThreadProcSafe
004acf26 PoolingDemoVCL.exe madExcept              ThreadExceptFrame
7536343b kernel32.dll                              BaseThreadInitThunk

memory dump: 
0886ab38  f0 0e 81 00 28 8e c4 05                            ....(...

allocation number: 9761
program up time: 3.30 s
type: GetMem
address: $8868e58
size: 8
access rights: read/write

thread $d54 (TThreadPool.TQueueWorkerThread):
671a536b madExcept32.dll    madExceptDbg      1736 GetMemCallback
007fa27a PoolingDemoVCL.exe IBCCallUni             TGDSList.FindGDS
00406f24 PoolingDemoVCL.exe System            4799 @GetMem
007fc8d3 PoolingDemoVCL.exe IBCCallUni             TGDS.RegisterNotification
0080e123 PoolingDemoVCL.exe IBCClassesUni          TGDSConnection.InitGDS
0080fe29 PoolingDemoVCL.exe IBCClassesUni          TGDSConnection.Connect
007c0c4b PoolingDemoVCL.exe CRConnectionPool       TCRLocalConnectionPool.OpenConnector
007c072d PoolingDemoVCL.exe CRConnectionPool       TCRLocalConnectionPool.GetConnection
007c12f1 PoolingDemoVCL.exe CRConnectionPool       TCRConnectionPoolManager.InternalGetConnection
007c13a1 PoolingDemoVCL.exe CRConnectionPool       TCRConnectionPoolManager.GetConnection
0078ec51 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.GetIConnection
007f1a09 PoolingDemoVCL.exe Uni                    TUniConnection.CheckProvider
0078ea2a PoolingDemoVCL.exe DBAccess               TCustomDAConnection.CreateIConnection
007f1d9e PoolingDemoVCL.exe Uni                    TUniConnection.CreateIConnection
0078f406 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.DoConnect
007f1fbf PoolingDemoVCL.exe Uni                    TUniConnection.DoConnect
0078f839 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.PerformConnect
007927f6 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.SetConnected
0078f7c4 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.Connect
0083350b PoolingDemoVCL.exe Unit1               30 CreateTask$ActRec.$0$Body
00685f85 PoolingDemoVCL.exe System.Threading  2055 TTask.Execute
00686cf5 PoolingDemoVCL.exe System.Threading  2390 TTask.InternalExecute
00686de9 PoolingDemoVCL.exe System.Threading  2417 TTask.InternalWork
0068ac69 PoolingDemoVCL.exe System.Threading  3341 TThreadPool.TQueueWorkerThread.ExecuteWorkItem
0068a8eb PoolingDemoVCL.exe System.Threading  3270 TThreadPool.TQueueWorkerThread.Execute
004acfdb PoolingDemoVCL.exe madExcept              HookedTThreadExecute
004ec3d9 PoolingDemoVCL.exe System.Classes   15048 ThreadProc
0040a72c PoolingDemoVCL.exe System           24940 ThreadWrapper
004acec1 PoolingDemoVCL.exe madExcept              CallThreadProcSafe
004acf26 PoolingDemoVCL.exe madExcept              ThreadExceptFrame
7536343b kernel32.dll                              BaseThreadInitThunk

memory dump: 
08868e58  f0 0e 81 00 88 85 c4 05                            ........

allocation number: 4167
program up time: 3.04 s
type: GetMem
address: $34a28d8
size: 8
access rights: read/write

main thread ($154):
671a536b madExcept32.dll    madExceptDbg      1736 GetMemCallback
004d85d6 PoolingDemoVCL.exe System.Classes    4882 TList.SetCapacity
00406f24 PoolingDemoVCL.exe System            4799 @GetMem
007fc8d3 PoolingDemoVCL.exe IBCCallUni             TGDS.RegisterNotification
004d8d5b PoolingDemoVCL.exe System.Classes    5104 TThreadList.UnlockList
007fa2f6 PoolingDemoVCL.exe IBCCallUni             TGDSList.GetGDS
0080e123 PoolingDemoVCL.exe IBCClassesUni          TGDSConnection.InitGDS
0080fe29 PoolingDemoVCL.exe IBCClassesUni          TGDSConnection.Connect
007c0c4b PoolingDemoVCL.exe CRConnectionPool       TCRLocalConnectionPool.OpenConnector
007c072d PoolingDemoVCL.exe CRConnectionPool       TCRLocalConnectionPool.GetConnection
007c12f1 PoolingDemoVCL.exe CRConnectionPool       TCRConnectionPoolManager.InternalGetConnection
007c13a1 PoolingDemoVCL.exe CRConnectionPool       TCRConnectionPoolManager.GetConnection
0078ec51 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.GetIConnection
007f1a09 PoolingDemoVCL.exe Uni                    TUniConnection.CheckProvider
0078ea2a PoolingDemoVCL.exe DBAccess               TCustomDAConnection.CreateIConnection
007f1d9e PoolingDemoVCL.exe Uni                    TUniConnection.CreateIConnection
0078f406 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.DoConnect
007f1fbf PoolingDemoVCL.exe Uni                    TUniConnection.DoConnect
0078f839 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.PerformConnect
007927f6 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.SetConnected
0078f7c4 PoolingDemoVCL.exe DBAccess               TCustomDAConnection.Connect
008338c8 PoolingDemoVCL.exe Unit1               58 BecauseMemoryLeakCheckFailsinD10Console
00833bb0 PoolingDemoVCL.exe Unit1               83 TForm1.FormCreate
00664965 PoolingDemoVCL.exe Vcl.Forms         3822 TCustomForm.DoCreate
00664571 PoolingDemoVCL.exe Vcl.Forms         3705 TCustomForm.AfterConstruction
00664523 PoolingDemoVCL.exe Vcl.Forms         3695 TCustomForm.Create
0066fb62 PoolingDemoVCL.exe Vcl.Forms        10843 TApplication.CreateForm
00841bd5 PoolingDemoVCL.exe PoolingDemoVCL      17 initialization
7536343b kernel32.dll                              BaseThreadInitThunk

memory dump: 
034a28d8  f0 0e 81 00 e8 79 c4 05                            .....y..
In the Real Wold one doesn't get reproducible demos from clients, and what I supplied earlier should have been more than enough..

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Possible Memory Leak with Pooling and Firebird (7.5.13)

Post by ViktorV » Fri 05 Jul 2019 07:37

Thank you for the information and your contribution in our product development. We have reproduced and fixed the issue. This fix will be included in the next build of UniDAC.
Since you have UniDAC Professional Edition with source code, you can try the following method to solve the issue. Open the file IBCCallUni.pas and replace in TGDS.Destroy

Code: Select all

    for i := 0 to FNotifications.Count - 1 do begin
      pEvent := PNotificationRec(FNotifications[i]);
      TMethod(NotificationEvent).Code := pEvent^.Code;
      TMethod(NotificationEvent).Data := pEvent^.Data;
      NotificationEvent;
    end;
with

Code: Select all

    for i := FNotifications.Count - 1 downto 0 do begin
      pEvent := PNotificationRec(FNotifications[i]);
      TMethod(NotificationEvent).Code := pEvent^.Code;
      TMethod(NotificationEvent).Data := pEvent^.Data;
      NotificationEvent;
      UnRegisterNotification(NotificationEvent);
    end;
We can compile and send you the nigthly build of UniDAC Professional Edition. Please indicate your IDE version, and we’ll send you the nightly build.

Post Reply