I would assume so since that type of Timer is “single-use”.
In your own Timer, you should use WeakAddressOf where the method belongs to an instance of a class and make sure the Timer is torn down properly in the class’ Destructor.
Matin, that’s not exactly true. WeakAddressOf does not increment the reference count on the object to which the method belongs, but that’s not the same as removing it.
You do not use AddHandler when using Xojo.Core.Timer.Calllater, so no need to remove handlers. You might want to test if the object the method belongs to still exists, anyway.
Yes, you can use both a AddressOf-RemoveHandler or a WeakAddressOf in a Timer.
I have had a few people send emails to me in the past with troubled timer code, and the reason why I suggest using an AddressOf-RemoveHandler pair is that the coder has absolute control over when the AddressOf is initiated and removed and its use is explicit. WeakAddressOf removal is implicit - meaning it is understood that at a given portion of the code the RemoveHandler will be automatically called. If your an experienced programmer and have used it a lot, then there isn’t a concern. If you are starting to use handlers, then I would suggest using the pair.
In my humble opinion, using AddressOf-RemoveHandler makes it clearer when the handler is removed. I personally prefer using code that is explicit, as it takes the guess out of it.
[quote=361859:@Eugene Dakin]
I have had a few people send emails to me in the past with troubled timer code, and the reason why I suggest using an AddressOf-RemoveHandler pair is that the coder has absolute control over when the AddressOf is initiated and removed and its use is explicit. WeakAddressOf removal is implicit - meaning it is understood that at a given portion of the code the RemoveHandler will be automatically called. [/quote]
This is incorrect
Using Weak Address of does NOT automatically remove the handler
However IF the target of the weakaddress of is destroyed the handler may refer to something that is now nil
But the handler is still in place and you could then get a nil object exception because the target of the handler no longer exists
Destroying the object that you added handlers to with AddHandler, in this case the timer, would remove the handlers