I have a class which recurses through a number of files for keywords and builds a list of these keywords.
I have reduced the code to merely a shell but still get a memory leak - what am I doing wrong?
Uses Classes, SysUtils, StrUtils;
Type
TKeywords = Class(TObject)
private
fIdentifiers: String;
fDefines: String;
fConstants: String;
fSubroutines: String;
fProcedures: String;
fParameters: String;
fMacros: String;
fAliases: String;
fIncludes: TStringlist;
public
constructor Create;
destructor Destroy;
procedure Execute(pFileName: String);
property Includes: TStringlist read fIncludes;
property Identifiers: String read fIdentifiers;
property Defines: String read fDefines;
property Constants: String read fConstants;
property Subroutines: String read fSubroutines;
property Procedures: String read fProcedures;
property Parameters: String read fParameters;
property Macros: String read fMacros;
property Aliases: String read fAliases;
end;
var Keywords: TKeywords;
implementation
Constructor Tkeywords.Create;
begin
inherited create;
fIncludes := TStringlist.Create;
end;
Destructor TKeywords.Destroy;
begin
fIncludes.Free;
inherited destroy;
end;
procedure TKeywords.Execute(pFileName: string);
begin
fIncludes.Add(pFileName);
end;
initialization
Keywords := Tkeywords.create;
finalization
Keywords.Free;
The memory leak reports: 1 x Unicodestring and 1 x StringList
Debug shows the destructor never gets called although it reaches Keywords.Free. Why is this?