From 09a18f463126ef0ac11bcbc786fca9b562a92320 Mon Sep 17 00:00:00 2001 From: Mike Brashler Date: Sun, 13 Oct 2024 18:15:50 -0700 Subject: [PATCH] Fix memory leaks --- DXCC.pas | 12 ++++++++++-- Main.pas | 4 ++++ NaQp.pas | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/DXCC.pas b/DXCC.pas index c23daee..c7031f6 100644 --- a/DXCC.pas +++ b/DXCC.pas @@ -3,6 +3,7 @@ interface uses + Generics.Collections, Classes; type @@ -18,12 +19,13 @@ TDXCCRec= class TDXCC= class private - DXCCList: TList; + DXCCList: TObjectList; procedure LoadDxCCList; procedure Delimit(var AStringList: TStringList; const AText: string); function SearchPrefix(out index : integer; const ACallPrefix : string) : Boolean; public constructor Create; + destructor Destroy; override; function FindRec(out dxrec : TDXCCRec; const ACallsign : string) : Boolean; function GetStationInfo(const ACallsign: string): string; function Search(ACallsign: string): string; @@ -46,7 +48,7 @@ procedure TDXCC.LoadDxCCList; slst:= TStringList.Create; tl:= TStringList.Create; try - DXCCList:= TList.Create; + DXCCList:= TObjectList.Create; slst.LoadFromFile(ParamStr(1) + 'DXCC.LIST'); // The search algorithm walks this list in reverse order. @@ -77,6 +79,12 @@ constructor TDXCC.Create; LoadDxCCList; end; + +destructor TDXCC.Destroy; +begin + FreeAndNil(DXCCList); +end; + // search ARRL DXCC prefix records for given callsign prefix. function TDXCC.SearchPrefix(out index : integer; const ACallPrefix : string) : Boolean; var diff --git a/Main.pas b/Main.pas index 0edf1bb..dcd593f 100644 --- a/Main.pas +++ b/Main.pas @@ -423,6 +423,10 @@ function Edit2IsRST: Boolean; procedure TMainForm.FormCreate(Sender: TObject); begin +{$ifdef DEBUG} + // detect/report memory leaks while in debug mode + System.ReportMemoryLeaksOnShutdown := True; +{$endif} Randomize; Panel2.DoubleBuffered := True; diff --git a/NaQp.pas b/NaQp.pas index fa68b56..db40774 100644 --- a/NaQp.pas +++ b/NaQp.pas @@ -19,7 +19,7 @@ TNaQpCallRec = class TNcjNaQp = class(TDualExchContest) private - NaQpCallList: TList; + NaQpCallList: TObjectList; Comparer: IComparer; public @@ -202,7 +202,7 @@ constructor TNcjNaQp.Create; begin inherited Create(etOpName, etNaQpExch2, // NA station exchange etOpName, etNaQpNonNaExch2); // non-NA station exchange - NaQpCallList := TList.Create; + NaQpCallList := TObjectList.Create; Comparer := TComparer.Construct(TNaQpCallRec.compareCall); end;