Link to home
Start Free TrialLog in
Avatar of oris
oris

asked on

Out of timers

Hi,

My application uses a lot of timers while running.
After a few days of running, it is unable to create timers., i.e.
it is unable to execute "TTimer.Create", probably because of lack of system resources.
Even when I restart my application it still happens, and only when I reboot the computer I can continue working.

I work on windows NT 4.0 service pack 3 and Delphi 3.
I am pretty sure that I do free every timer I use, and I am suspecting that the NT has a limit for using timers.
I have checked for memory and resource leaks using TurboPower's Memory Sleuth, and there were no leaks.

Thanks,
  Ori.
Avatar of Motaz
Motaz

Make sure that you assign nil to Timer.OnTimer

Motaz
How many timers are you using at once?

for what purpose?
There IS a limit on th number of timers that Windows can support simultaneously (can't remember what it is but 8 seems to be familair). Have you thought about using threads?

The Neil =:(
you must release the timer when you don't need it.

I think you don't need so many timer.you can do it like this

var
 aTimeCounter:array of [0..255] of integer;
 aTimeLimit:array of [0..255] of integer;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  i:integer;
begin
  for i:=0 to 255 do
  begin
    Inc(aTimeCounter[i]);
    if aTimeCounter[i]>aTimerLimit then
    begin
      //PostMessage or SendMessage
      aTimeCounter[i]:=0;
    end;
  end;
end;

Hello,

you said you are sure you free a the timers. In order to check if that's right. Put a counter for created and a counter for freed timers. If there's a difference you know it definitely.

In order to free the timer use FreeAndNil("Timer") in order to force the Timer to be removed from the memory.

Good luck, Martin
Hey msedit, thanks for the 'freeandnil' proc !

I've been using Delphi for 5 years, and I have never seen it !

Thanks, you can always learn...
FreeAndNil is new in Delphi 5....
Avatar of oris

ASKER

Adjusted points from 250 to 300
Avatar of oris

ASKER

msedi:
I did try putting counters and the results were (num of creates) - (num of frees) = 0.
I use Delphi 3, so I don't have the ability to use "FreeAndNil".

I suspect that NT has an absolute limit for using timers during an NT session.
ASKER CERTIFIED SOLUTION
Avatar of msedi
msedi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I cannot image that there would be a timer restriction in NT. How many timers do you have to create from a fresh boot of the system until you get the error?
Try to do something like this to test it:

var i1 : integer;
begin
  for i1 := 0 to 10000 do
    with TTimer.Create do
      try
        // here set all the properties
      finally Free end;

Does this simple program fail, too? Then it's the proove that either the TTimer component or Windows itself has a bug or restriction.

Regards, Madshi.
Avatar of oris

ASKER

I did some experiments, and there is a very good chance that I have a bug somewhere else in my program.

Martin,
I appreciate your efforts, so I will accept your comment as the answer.
Thanks,
Ori.
oris@math.tau.ac.il