1
0
mirror of synced 2024-11-24 11:43:07 +01:00

Fixed: memory leak when using MonitorForm

Changed: TX2LogBaseClient is now reference-counted
This commit is contained in:
Mark van Renswoude 2014-05-30 13:06:47 +00:00
parent 6d5355e0b6
commit acd998a845
7 changed files with 17 additions and 17 deletions

View File

@ -25,6 +25,8 @@ var
MainForm: TMainForm; MainForm: TMainForm;
begin begin
ReportMemoryLeaksOnShutdown := True;
Application.Initialize; Application.Initialize;
Application.MainFormOnTaskbar := True; Application.MainFormOnTaskbar := True;
Application.Title := 'X²LogTest'; Application.Title := 'X²LogTest';

View File

@ -30,10 +30,8 @@ object MainForm: TMainForm
Align = alClient Align = alClient
Images = ilsObservers Images = ilsObservers
TabOrder = 0 TabOrder = 0
ExplicitHeight = 305
object tsEvent: TTabSheet object tsEvent: TTabSheet
Caption = 'Event Observer ' Caption = 'Event Observer '
ExplicitHeight = 277
object mmoEvent: TMemo object mmoEvent: TMemo
AlignWithMargins = True AlignWithMargins = True
Left = 8 Left = 8
@ -48,7 +46,6 @@ object MainForm: TMainForm
ReadOnly = True ReadOnly = True
ScrollBars = ssVertical ScrollBars = ssVertical
TabOrder = 0 TabOrder = 0
ExplicitHeight = 229
end end
object btnEventStart: TButton object btnEventStart: TButton
Left = 8 Left = 8
@ -71,7 +68,6 @@ object MainForm: TMainForm
end end
object tsFile: TTabSheet object tsFile: TTabSheet
Caption = 'File Observer' Caption = 'File Observer'
ExplicitHeight = 277
object lblFilename: TLabel object lblFilename: TLabel
Left = 12 Left = 12
Top = 64 Top = 64
@ -134,7 +130,6 @@ object MainForm: TMainForm
end end
object tsNamedPipe: TTabSheet object tsNamedPipe: TTabSheet
Caption = 'Named Pipe Observer' Caption = 'Named Pipe Observer'
ExplicitHeight = 277
object lblPipeName: TLabel object lblPipeName: TLabel
Left = 12 Left = 12
Top = 64 Top = 64
@ -183,7 +178,6 @@ object MainForm: TMainForm
Align = alBottom Align = alBottom
BevelOuter = bvNone BevelOuter = bvNone
TabOrder = 1 TabOrder = 1
ExplicitTop = 482
object btnClose: TButton object btnClose: TButton
Left = 520 Left = 520
Top = 0 Top = 0
@ -318,7 +312,7 @@ object MainForm: TMainForm
Left = 552 Left = 552
Top = 176 Top = 176
Bitmap = { Bitmap = {
494C01010200140028000C000C00FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600 494C0101020014002C000C000C00FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
0000000000003600000028000000300000000C00000001002000000000000009 0000000000003600000028000000300000000C00000001002000000000000009
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000

View File

@ -107,6 +107,8 @@ begin
SetLogResourceString(@LogMonitorFormButtonSaveDetails, 'Opslaan'); SetLogResourceString(@LogMonitorFormButtonSaveDetails, 'Opslaan');
SetLogResourceString(@LogMonitorFormStatusPaused, 'Gepauseerd: %d melding(en) overgeslagen'); SetLogResourceString(@LogMonitorFormStatusPaused, 'Gepauseerd: %d melding(en) overgeslagen');
SetLogResourceString(@LogMonitorFormSaveDetailsFilter, 'Alle bestanden (*.*)|*.*');
FLog := TX2Log.Create; FLog := TX2Log.Create;
FLog.SetExceptionStrategy(TX2LogmadExceptExceptionStrategy.Create); FLog.SetExceptionStrategy(TX2LogmadExceptExceptionStrategy.Create);

View File

@ -9,7 +9,7 @@ uses
type type
TX2LogBaseClient = class(TInterfacedPersistent, IX2LogBase, IX2LogObservable) TX2LogBaseClient = class(TInterfacedObject, IX2LogBase, IX2LogObservable)
private private
FObservers: TList<IX2LogObserver>; FObservers: TList<IX2LogObserver>;
protected protected

View File

@ -11,7 +11,7 @@ uses
type type
TX2GlobalLog = class(TObject) TX2GlobalLog = class(TObject)
private class var private class var
FInstance: TX2Log; FInstance: IX2Log;
protected protected
class procedure CleanupInstance; class procedure CleanupInstance;
public public
@ -59,8 +59,7 @@ end;
class procedure TX2GlobalLog.CleanupInstance; class procedure TX2GlobalLog.CleanupInstance;
begin begin
if Assigned(FInstance) then FInstance := nil;
FreeAndNil(FInstance);
end; end;

View File

@ -102,8 +102,6 @@ object X2LogObserverMonitorForm: TX2LogObserverMonitorForm
ReadOnly = True ReadOnly = True
ScrollBars = ssBoth ScrollBars = ssBoth
TabOrder = 1 TabOrder = 1
ExplicitLeft = -2
ExplicitWidth = 348
end end
end end
end end
@ -154,7 +152,7 @@ object X2LogObserverMonitorForm: TX2LogObserverMonitorForm
end end
item item
Position = 2 Position = 2
Width = 424 Width = 428
WideText = 'Message' WideText = 'Message'
end> end>
end end
@ -202,7 +200,7 @@ object X2LogObserverMonitorForm: TX2LogObserverMonitorForm
Left = 448 Left = 448
Top = 48 Top = 48
Bitmap = { Bitmap = {
494C010109004000880010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600 494C0101090040008C0010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
0000000000003600000028000000400000003000000001002000000000000030 0000000000003600000028000000400000003000000001002000000000000030
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000

View File

@ -60,7 +60,7 @@ type
procedure actSaveDetailsExecute(Sender: TObject); procedure actSaveDetailsExecute(Sender: TObject);
procedure actPauseExecute(Sender: TObject); procedure actPauseExecute(Sender: TObject);
private class var private class var
FInstances: TDictionary<IX2Log,TX2LogObserverMonitorForm>; FInstances: TObjectDictionary<IX2Log,TX2LogObserverMonitorForm>;
private private
FFreeOnClose: Boolean; FFreeOnClose: Boolean;
FLogToAttach: IX2Log; FLogToAttach: IX2Log;
@ -160,7 +160,7 @@ begin
log := (ALog as IX2Log); log := (ALog as IX2Log);
if not Assigned(FInstances) then if not Assigned(FInstances) then
FInstances := TDictionary<IX2Log,TX2LogObserverMonitorForm>.Create; FInstances := TObjectDictionary<IX2Log,TX2LogObserverMonitorForm>.Create([doOwnsValues]);
if not FInstances.TryGetValue(log, Result) then if not FInstances.TryGetValue(log, Result) then
begin begin
@ -619,4 +619,9 @@ begin
UpdateStatus; UpdateStatus;
end; end;
initialization
finalization
TX2LogObserverMonitorForm.CleanupInstances;
end. end.