Dim As New Question

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 ?

Any advice appreciated.

Dim as new whatever will run every time
And that will get you the current date & time when the timer action event goes
That’s probably what you want

So the old CurrentTime is destroyed in memory by the new Dim ?

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.

Ok, so once I exit the action it’s destroyed. That’s the behaviour I wanted. Thanks for the reply.

I come from an Objective-C background pre- ARC and am very conscious of not wanting to leave things laying around.

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

That’s great, thank you

Xojo takes care of so many of these kinds of things automagically that you get a little spoiled.

More than a little spoiled.