Delphi TTimer interval limitation

[ DelphiLand FAQ ]

Posted by webmaster Guido on March 14, 2004 at 17:40:19:

In Reply to: Re: Thx and... posted by Joey on March 11, 2004 at 22:17:31:

: With TTimer running does it slowly churn up memery or each cycle does it clean up what it last did??

: So with it set to 1 it wont very very slowly cause my PC to slow down will it??

1. TTimer events do not accumulate memory every time they run, just as any other event doesn't do this. Otherwise, the system would hang very quickly, since so many messages are buzzing around continuously between the OS (Windows) and the applications.

Of course, you could *code* the event handler the wrong way, so that it eats a bit of memory each time, without releasing the previous memory. An example would be: in the OnTimer procedure, create an object of your own, and afterwards forget to free that object:

MyList: TList;
procedure TForm1.Timer1Timer(Sender: TObject);
MyList := TList.Create;
{ Next, do some things with MyList,
whithout FREEING Mylist

2. The real resolution of the TTimer interval is limited to 55 milliseconds: the real interval is not what you set, but a multiple of 55. Meaning: if you set it to any value from 1 to 55 it will be 55, 56 to 110 gives 110, and so on.
That's a limitation set by Windows, because your Delphi application only gets attention of the Windows OS about 18 times per second (it gets "time slices"). Conclusion: even setting the TTimer interval to 1 won't slow down the PC (unless you'd block the system in your timer event procedure :)

Related Articles and Replies:

[ DelphiLand: free Delphi source code, tips, tutorials ]