Reusing Timers, Serials & TCPSockets

I use several timers as well as a serial control and a TCP socket in a service app that is designed to run continuously and may connect to different IP addresses or serial ports. I know that if this were a desktop app, I could place them on the desktop as controls and I would only have one instance of each one. Both the TCPSocket and the Serial control are subclassed and I create an instance of one or the other depending on what is specified in the database for the device to communicate with.

In creating a watchdog timer to clean up things if the system were to hang for some unknown reason outside my control, it occurred to me that using a single instance might be a better approach. Some of my timers are instantiated when execution starts and some get a new instance whenever one is needed. Is one way better than the other? If I use a new instance each time, do I need to set the old one to NIL first?

No. And I don’t think there’s a huge difference in creating a new one vs. reusing an old Timer. If you’re talking about the sockets, then there may be an advantage to creating a new one, as you get a pristine instance each time and don’t have to worry about any settings being carried forward.

Thanks Tim

I use timers/threads for a single task each for each instance of them. I am not worried about the few microseconds it takes to make one. Generally it is so few that I dont notice them in the profiler.