local function RemoveFromArray(TimerObj)
table.remove(TimerArrays, table.find(TimerArrays, TimerObj))
end
If :Stop() or :Pause() is accidentally called on a timer that was never started then this function will remove the last item from the TimerArrays table. Needs to look like this instead.
local function RemoveFromArray(TimerObj)
local index = table.find(TimerArrays, TimerObj)
if index then
table.remove(TimerArrays, index)
end
end
@Dued1 Good catches, especially for the latter ones.
I’m unsure regarding the binary search algorithm since it was provided to be by CntKillMe, and after looking through other sources they use math.floor too. I’ll do some extra research before properly taking care of the issue.
Validates that the timer object has been started before removing it from the priority queue.
Fixed issues with binary search algorithm; the issue lied in the fact that since the binary search algorithm was translated from roblox-ts in which arrays start at 0 rather than 1, I forgot to add a + 1 within the code where I grab the middle timer. I have rewritten the algorithm function to function on a 1-based index rather than a 0-based index (thank you CntKillMe again).
Do the timer objects created garbage collect themselves or do they just get removed when the timer ends? I don’t see a method to destroy or otherwise set the timer object to nil in the documentation, is that by deign?
How can we be sure they are cleaned up and not causing memory leaks?
I noticed that the callbacks for the states “Died” and “Dead” do not fire. This may be intended, but if so I am not sure how to fire a function if it is Stopped. We can fire a function if it is Finished yes, but what if we kill it before its finished.
Sorry, I’m not well-versed in this area of expertise, and no one I knew was available to help me determine whether this would cause any memory leaks. I’ve been using it fine for a while without any noticeable memory increases, though.
There doesn’t appear to be anything in his code that would cause a memory leak, it looks like if you want to get rid of a timer object that you should cancel it’s timer if it is active and set any references you have to it to nil and it will garbage collect.
That’s what I’ve been hoping to see since I began learning Roblox Studio. Previously, I was a Unity developer and wanted to learn something way beyond it. When I started to learn Roblox Studio, it was really hard to get used to using wait instead of a timer. Thank you!