Wiem gdzie jest wyciek (zaznaczone w kodzie poniżej), ale nie potrafię tego poprawić, a mianowicie:
Jest to część z komponentu TDirMonitor do informowania o wszelkich zapisach, odczytach na dysku.
TDirMonitor = class(TComponent)
protected
FDir:string;
Mon:TProcessMonitor; // <--------- moduł
FEventChange: TEventChange;
FActive: Boolean;
procedure W_FActive(Value: boolean);
procedure Loaded; override;
procedure MakeMask;
public
FCompletionPort: Integer;
FOverlapped: TOverlapped;
FPOverlapped: POverlapped;
FBytesWrite: DWORD;
FNotificationBuffer: array[0..4096] of Byte;
FHandle: integer;
FWatchSubtree: boolean;
FFilter: DWORD;
FFilter_flag: TFilter;
FActionFilter_flag: TActionFilter;
constructor Create(Owner:TComponent); override;
destructor Destroy;override;
procedure RecibirEvento;
published
property Directory: string read FDir write Fdir;
property WatchSubtree: boolean read FWatchSubtree write FWatchSubtree default false;
property FilterNotification: TFilter read FFilter_flag write FFilter_flag;
property FilterAction: TActionFilter read FActionFilter_flag write FActionFilter_flag;
property OnChange: TEventChange read FEventChange write FEventChange;
property Active: boolean read FActive write W_FActive default false;
end;
//...
constructor TDirMonitor.Create(Owner: TComponent);
begin
inherited;
FPOverlapped := @FOverlapped;
self.FCompletionPort:=0;
self.FDir:='c:\';
self.FFilter_flag:=[nfFILE_NAME];
self.FActionFilter_flag := [faADDED, faREMOVED, faMODIFIED, faRENAMED_OLD_NAME, faRENAMED_NEW_NAME];
Mon := TProcessMonitor.Create(self); { <----------------- TUTAJ WYCIEK}
end;
destructor TDirMonitor.Destroy;
begin
Mon.Terminate;
inherited;
end;
//... dalsza część kodu nie znacząca
Oraz moduł TProcessMonitor w który nie jest zwalniany
unit ProcessMonitor;
interface
uses
Classes, Windows, SysUtils;
type
TProcessMonitor = class(TThread)
private
{ Private declarations }
protected
FProRef: TComponent;
procedure Execute; override;
procedure SendEvent;
public
FHandle: integer;
constructor Create(ProRef: TComponent); overload;
end;
implementation
{ TMonitor }
uses DirMonitor;
constructor TProcessMonitor.Create(ProRef: TComponent);
begin
Self.Create(True);
Self.FProRef := ProRef;
Self.Priority := tpNormal; //tpTimeCritical;
FreeOnTerminate := True;
end;
//... dalsza część kodu nie znacząca