I have a timer running at Intervals of one minute. I have added an action that whenever the timer reaches it’s interval it fires off the following code
Dim CurrentTime As New Date
TimeDateIndicator.Text = CurrentTime.ShortDate + " " + CurrentTime.ShortTime
However, should I be doing this in this way ? Shouldn’t Dim As New only be run once ?
its actually destroyed when you exit this method unless you have some other code hanging on to it somehow.
It sounds like you’re asking “am I creating a huge pile of these things laying around?”.
If the code you posted is all of it you create the date object, use it then it’s thrown away when the action event code finishes.
Objects are reference counted.
So in this case it goes out of scope, reference counts are decremented & its gone.
The same is true if you did
Dim CurrentTime As New Date // you create one here so its ref count = 1
CurrentTime = new Date // a new one is created & replaces the old one
// the old ones ref count = 0 and its destroyed
// the new ones ref count = 1