Solved

Out of timers

Posted on 2000-04-19
12
262 Views
Last Modified: 2010-04-04
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.
0
Comment
Question by:oris
12 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 2730528
Make sure that you assign nil to Timer.OnTimer

Motaz
0
 
LVL 7

Expert Comment

by:God_Ares
ID: 2730648
How many timers are you using at once?

for what purpose?
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2730708
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 =:(
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 3

Expert Comment

by:shenqw
ID: 2730746
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;

0
 
LVL 1

Expert Comment

by:msedi
ID: 2730864
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
0
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2730943
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...
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2731620
FreeAndNil is new in Delphi 5....
0
 

Author Comment

by:oris
ID: 2736635
Adjusted points from 250 to 300
0
 

Author Comment

by:oris
ID: 2736636
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.
0
 
LVL 1

Accepted Solution

by:
msedi earned 300 total points
ID: 2746501
Hello,

sorry I couldn't find anything whether there is a restriction to the timer. Just look in the Win32 API Help. But I will have a look in the MSDN maybe there's an answer. By the way Epsylon is right FreeAndNil is new in D5. Here's the code of FreeAndNil, it's rather simple:

procedure FreeAndNil(var Obj);
var
  P: TObject;
begin
  P := TObject(Obj);
  TObject(Obj) := nil;  // clear the reference before destroying the object
  P.Free;
end;


Good luck,
Martin
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2746547
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.
0
 

Author Comment

by:oris
ID: 2749347
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
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question