Title: Strange memory leak after connection exception
Post by: Dany on August 11, 2018, 02:19:56 PM
Hello again! I have an ... where do i attach files to a topic??!! Ok ... i have a small MVP that behaves strangely. Seems i cannot attach a zip in this forum, the code is pasted below, .dpr, .dfm and .pas. I can click the first three buttons to my hearts content and terminate the application. Good. If i click the fourth button (arg... that's Button3 not Button4, sorry), there is a memory leak reported when the application terminates. The fourth server is behind a firewall. I'm not sure about the dns name, if it can be looked up outside of that firewall. Any insights would be appreciated! /D program Project11;
uses Vcl.Forms, Unit19 in 'Unit19.pas' {Form19};
{$R *.res}
begin ReportMemoryLeaksOnShutdown := true;
Application.Initialize; Application.MainFormOnTaskbar := True; Application.CreateForm(TForm19, Form19); Application.Run; end.
... object Form19: TForm19 Left = 0 Top = 0 Caption = 'Form19' ClientHeight = 45 ClientWidth = 530 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 object Button1: TButton Left = 8 Top = 8 Width = 75 Height = 25 Caption = 'localhost' TabOrder = 0 OnClick = Button1Click end object Button2: TButton Left = 89 Top = 8 Width = 75 Height = 25 Caption = 'IP 10.0.2.2' TabOrder = 1 OnClick = Button2Click end object Button3: TButton Left = 383 Top = 8 Width = 130 Height = 25 Caption = 'smrihs02.ekuc.se' TabOrder = 2 OnClick = Button3Click end object Button4: TButton Left = 170 Top = 8 Width = 207 Height = 25 Caption = 'big site of extremely commercial paper' TabOrder = 3 OnClick = Button4Click end object rhcMain: TRtcHttpClient ServerAddr = 'localhost' ServerPort = '81' ReconnectOn.ConnectError = True ReconnectOn.ConnectLost = True ReconnectOn.ConnectFail = True AutoConnect = True Left = 14 Top = 13 end object cmMain: TRtcClientModule AutoSyncEvents = True Client = rhcMain Compression = cDefault AutoSessionMode = rsm_Cookie ObjectLinks = ol_AutoClient AutoSessions = True ModuleFileName = '/mytest' Left = 53 Top = 14 end end
... unit Unit19;
interface
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, rtcSystem, rtcInfo, rtcConn, rtcDataCli, rtcHttpCli, rtcCliModule;
type TForm19 = class(TForm) rhcMain: TRtcHttpClient; Button1: TButton; Button2: TButton; Button3: TButton; cmMain: TRtcClientModule; Button4: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form19: TForm19;
implementation
{$R *.dfm}
procedure TForm19.Button1Click(Sender: TObject); begin rhcMain.ServerAddr := 'localhost'; rhcMain.ServerPort := '80';
cmMain.Prepare('hello'); cmMain.Execute; end;
procedure TForm19.Button2Click(Sender: TObject); begin rhcMain.ServerAddr := '10.0.2.2'; rhcMain.ServerPort := '81';
cmMain.Prepare('hello'); cmMain.Execute; end;
procedure TForm19.Button4Click(Sender: TObject); begin rhcMain.ServerAddr := 'www.aftonbladet.se'; rhcMain.ServerPort := '443';
cmMain.Prepare('hello'); cmMain.Execute; end;
procedure TForm19.Button3Click(Sender: TObject); begin rhcMain.ServerAddr := 'smrihs02.ekuc.se'; rhcMain.ServerPort := '443';
cmMain.Prepare('hello'); cmMain.Execute; end;
end.
Title: Re: Strange memory leak after connection exception
Post by: D.Tkalcec (RTC) on August 11, 2018, 05:51:43 PM
Close the connection (call rhcMain.DisconnectNow) before you close the Application - for example, from your Main Form's "OnCloseQuery" event.
Title: Re: Strange memory leak after connection exception
Post by: Dany on August 12, 2018, 09:16:30 AM
I changed the code to below. Just added an OnCloseQuery handler... CanClose := rhcMain.DisconnectNow = wait_OK; ...but i get the same result ??? ! Could you take another look? Apologies if i am being daft. /D object Form19: TForm19 Left = 0 Top = 0 Caption = 'Form19' ClientHeight = 45 ClientWidth = 530 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False OnCloseQuery = FormCloseQuery PixelsPerInch = 96 TextHeight = 13 object Button1: TButton Left = 8 Top = 8 Width = 75 Height = 25 Caption = 'localhost' TabOrder = 0 OnClick = Button1Click end object Button2: TButton Left = 89 Top = 8 Width = 75 Height = 25 Caption = 'IP 10.0.2.2' TabOrder = 1 OnClick = Button2Click end object Button3: TButton Left = 383 Top = 8 Width = 130 Height = 25 Caption = 'smrihs02.ekuc.se' TabOrder = 2 OnClick = Button3Click end object Button4: TButton Left = 170 Top = 8 Width = 207 Height = 25 Caption = 'big site of extremely commercial paper' TabOrder = 3 OnClick = Button4Click end object rhcMain: TRtcHttpClient ServerAddr = 'localhost' ServerPort = '81' ReconnectOn.ConnectError = True ReconnectOn.ConnectLost = True ReconnectOn.ConnectFail = True AutoConnect = True Left = 14 Top = 13 end object cmMain: TRtcClientModule AutoSyncEvents = True Client = rhcMain Compression = cDefault AutoSessionMode = rsm_Cookie ObjectLinks = ol_AutoClient AutoSessions = True ModuleFileName = '/mytest' Left = 53 Top = 14 end end and unit Unit19;
interface
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, rtcSystem, rtcInfo, rtcConn, rtcDataCli, rtcHttpCli, rtcCliModule;
type TForm19 = class(TForm) rhcMain: TRtcHttpClient; Button1: TButton; Button2: TButton; Button3: TButton; cmMain: TRtcClientModule; Button4: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); private { Private declarations } public { Public declarations } end;
var Form19: TForm19;
implementation
uses rtcThrPool;
{$R *.dfm}
procedure TForm19.Button1Click(Sender: TObject); begin rhcMain.ServerAddr := 'localhost'; rhcMain.ServerPort := '80';
cmMain.Prepare('hello'); cmMain.Execute; end;
procedure TForm19.Button2Click(Sender: TObject); begin rhcMain.ServerAddr := '10.0.2.2'; rhcMain.ServerPort := '81';
cmMain.Prepare('hello'); cmMain.Execute; end;
procedure TForm19.Button4Click(Sender: TObject); begin rhcMain.ServerAddr := 'www.aftonbladet.se'; rhcMain.ServerPort := '443';
cmMain.Prepare('hello'); cmMain.Execute; end;
procedure TForm19.Button3Click(Sender: TObject); begin rhcMain.ServerAddr := 'smrihs02.ekuc.se'; rhcMain.ServerPort := '443';
cmMain.Prepare('hello'); cmMain.Execute; end;
procedure TForm19.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin CanClose := rhcMain.DisconnectNow = wait_OK; end;
end.
|