Unrooted Timers and Garbage Collection

For test results, bug reports, announcements of new builds etc.

Moderators: another_commander, winston, Getafix

Post Reply
User avatar
Nite Owl
---- E L I T E ----
---- E L I T E ----
Posts: 521
Joined: Sat Jan 20, 2018 4:08 pm
Location: In The Dark

Unrooted Timers and Garbage Collection

Post by Nite Owl »

Been getting a bunch of these lately.

Code: Select all

14:32:09.262 [script.javaScript.unrootedTimer]: ----- WARNING: Timer <OOJSTimer 0x1be6b5f0>{nextTime: 1674.12, one-shot, running, function: anonymous} is being garbage-collected while still running. You must keep a reference to all running timers, or they will stop unpredictably!
This particular example is anonymous so as to avoid pointing a finger at any one OXZ. As for other Unrooted Timers the Wiki and some previous posts have taught me how to identify them via code changes and binary searches. The point of this thread is to ask for help in how to stop them from being Garbage Collected at all.

The main problem is the final statement in the above code: You must keep a reference to all running timers, or they will stop unpredictably! This Stoppage of Timers is random and includes even those that are NOT being Garbage Collected. As mentioned elsewhere my Ooniverse has 300+ OXZs/OXPs involved in it operations. Most of the time this runs smoothly, but every now and again things go downhill when some of the Timers come to a screeching halt. This results in missed opportunities from nearly unplayable situations. Restarting the game remedies the problem but the intervening time to get to a station, save the game, and then restart it from that save is frustrating without the proper functionality. The alternative being to just quit the game while in flight, reload the last save, and loose any progress that has been made. Not an ideal solution but it has been used as a last resort.

Any and all help in this matter would be greatly appreciated.
Humor is the second most subjective thing on the planet

Brevity is the soul of wit and vulgarity is wit's downfall

Good Night and Good Luck - Read You Soon
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2412
Joined: Mon May 31, 2010 11:11 pm

Re: Unrooted Timers and Garbage Collection

Post by Switeck »

I wonder if a hyperspace jump while a bunch of timers are running could cause problems?
User avatar
Nite Owl
---- E L I T E ----
---- E L I T E ----
Posts: 521
Joined: Sat Jan 20, 2018 4:08 pm
Location: In The Dark

Re: Unrooted Timers and Garbage Collection

Post by Nite Owl »

Having looked at the code for a few of them most Timers stop when initiating a Hyperspace Jump and then turn back on once the Jump is complete. My best guess for this is that they should stop Timing in the system one is leaving and then start Timing again once the arrival system is populated. My gut is telling me that the Garbage Collection thing has to do with the way the Timer is coded. Exactly how and why one Timer's code Garbage Collects and another one's code does not Garbage Collect is what escapes me.
Humor is the second most subjective thing on the planet

Brevity is the soul of wit and vulgarity is wit's downfall

Good Night and Good Luck - Read You Soon
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4632
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Unrooted Timers and Garbage Collection

Post by phkb »

Nite Owl wrote: Thu Feb 02, 2023 9:08 pm
This Stoppage of Timers is random and includes even those that are NOT being Garbage Collected.
Actually, the reason isn’t random, although it may be obscure.

A lot of timers are attached to ship scripts. When that ship entity is removed (destroyed, docked at a station, or when all ships are despawned because you jumped to a new system), the scripts attached to them are also destroyed, including any timers that are linked to those scripts.

The other reason a timer might get garbage collected while running is if the timer is recreated without stopping the previous one. So, a timer is started when launching from a station, but it is never stopped. Then you dock and relaunch, and a new timer is started again, sending the previous one to the GC.

Tracking down the anonymous entries is annoying. What I’ve found is if the script that the timer is set to run is defined like this:

Code: Select all

this.myTimerFunction = function myTimerFunction() {
… code …
}
then the error message in the log will include the function name instead of anonymous, making identification much easier.
User avatar
Nite Owl
---- E L I T E ----
---- E L I T E ----
Posts: 521
Joined: Sat Jan 20, 2018 4:08 pm
Location: In The Dark

Re: Unrooted Timers and Garbage Collection

Post by Nite Owl »

Thank You phkb. When real life allows me to get back to playing on a regular basis your advice will be followed in an attempt to solve the problem.
Humor is the second most subjective thing on the planet

Brevity is the soul of wit and vulgarity is wit's downfall

Good Night and Good Luck - Read You Soon
Post Reply