From: <ah...@us...> - 2010-05-18 17:07:39
|
Revision: 12779 http://jvcl.svn.sourceforge.net/jvcl/?rev=12779&view=rev Author: ahuser Date: 2010-05-18 17:07:33 +0000 (Tue, 18 May 2010) Log Message: ----------- Mantis #5242: TjvThreadTimer memory leak. Object is not freed correctly. FreeOnTerminate makes things more tricky (Sleep(0)) and can cause memory leaks Modified Paths: -------------- trunk/jvcl/run/JvThreadTimer.pas Modified: trunk/jvcl/run/JvThreadTimer.pas =================================================================== --- trunk/jvcl/run/JvThreadTimer.pas 2010-05-16 21:22:20 UTC (rev 12778) +++ trunk/jvcl/run/JvThreadTimer.pas 2010-05-18 17:07:33 UTC (rev 12779) @@ -46,13 +46,7 @@ {$IFDEF UNITVERSIONING} JclUnitVersioning, {$ENDIF UNITVERSIONING} - {$IFDEF MSWINDOWS} - Windows, - {$ENDIF MSWINDOWS} - {$IFDEF UNIX} - QWindows, - {$ENDIF UNIX} - SysUtils, Classes, + Windows, SysUtils, Classes, JvTypes, JvComponentBase; type @@ -65,7 +59,6 @@ FPriority: TThreadPriority; FStreamedEnabled: Boolean; FThread: TThread; - function GetThread: TThread; procedure SetEnabled(const Value: Boolean); procedure SetInterval(const Value: Cardinal); procedure SetOnTimer(const Value: TNotifyEvent); @@ -79,7 +72,7 @@ public constructor Create(AOwner: TComponent); override; destructor Destroy; override; - property Thread: TThread read GetThread; + property Thread: TThread read FThread; published // (p3) renamed Active->Enabled, Delay->Interval to make it compatible with TTimer property Enabled: Boolean read FEnabled write SetEnabled default False; @@ -139,7 +132,6 @@ begin inherited Create(False); - FreeOnTerminate := True; { Manually reset = false; Initial State = false } FEvent := CreateEvent(nil, False, False, nil); if FEvent = 0 then @@ -206,7 +198,6 @@ SetEvent(FEvent); if Suspended then Suspended := False; - Sleep(0); end; //=== { TJvThreadTimer } ===================================================== @@ -215,12 +206,7 @@ begin inherited Create(AOwner); FInterval := 1000; - {$IFDEF MSWINDOWS} FPriority := tpNormal; - {$ENDIF MSWINDOWS} - {$IFDEF UNIX} - FPriority := 0; - {$ENDIF UNIX} end; destructor TJvThreadTimer.Destroy; @@ -243,11 +229,6 @@ end; end; -function TJvThreadTimer.GetThread: TThread; -begin - Result := FThread; -end; - procedure TJvThreadTimer.Loaded; begin inherited Loaded; @@ -306,9 +287,11 @@ procedure TJvThreadTimer.StopTimer; begin - if FThread is TJvTimerThread then + if FThread <> nil then + begin TJvTimerThread(FThread).Stop; - FThread := nil; + FreeAndNil(FThread); + end; end; procedure TJvThreadTimer.UpdateTimer; @@ -325,16 +308,17 @@ if DoEnable then begin - if FThread is TJvTimerThread then - TJvTimerThread(FThread).FInterval := FInterval + if FThread <> nil then + begin + TJvTimerThread(FThread).FInterval := FInterval; + if FThread.Suspended then + FThread.Suspended := False; + end else FThread := TJvTimerThread.Create(Self); - - if FThread.Suspended then - FThread.Suspended := False; end else - if FThread is TJvTimerThread then + if FThread <> nil then begin if not FThread.Suspended then TJvTimerThread(FThread).DoSuspend; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |