Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Anubis-class Cruiser (12/20/24)

Author Topic: Improvements to the memory leak warning.  (Read 1961 times)

Lukas04

  • Admiral
  • *****
  • Posts: 627
    • View Profile
Improvements to the memory leak warning.
« on: May 16, 2023, 10:11:11 AM »

Currently starsector has two methods to inform for a possible campaign engine memory leak.

1. A popup that warns about multiple campaign engines existing, while also telling the user to save and restart to prevent possible crashes.
2. A devmode exclusive message in the bottom left that mentions multiple campaign engines existing, only stopping if the amount of campaign engine instances goes back to 1.


I think the second method is quite useful as a mod developer.
It helped me track down two memory leaks in one of my own and in another mod before. Its faster than using visualvm for initial debugging and you are more likely to notice it, as most modders probably dont check on their game with visualvm daily.


However, in my opinion the first method is often less useful, and is often just wrong about its assesment.
It often seems to false trigger after reloading a save, which becomes more likely with the more mods you have, even if none of them actualy do have a memory leak. It seems that even if forced to, the garbage collector just occasionaly fails to get rid of the old CampaignEngine immediately even without a leak present.

My personal issue with it is that it informs the user of a possible leak, but unlike the second method, it never tells them that it may have been a false assesment in case there is only one engine again.
This often leads to confusion and misinformation among users, you can frequently see cases where someone installs a new mod, they get the pop up and they link the issue towards one of the mods they just downloaded, which in turn causes concerns for that mods author and the users.

Another issue with those false flags is that it conditions people to simply clicking it away, it happens so often that people just ignore the warning entirely.

I dont have many solutions to the issue myself, but i think there should be a bit longer of a buffer between reloading a save and the message being able to appear. Instead of a pop up, i think it would also do better if it was a warning in some corner of the screen, which keeps the user updated in case it is actually a false flag, similar to the current devmode warning.
But after discussions on the discord ive seen people have differing opinions on solutions too, so im sure there will be more in the replies.
« Last Edit: May 16, 2023, 10:13:06 AM by Lukas04 »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 25012
    • View Profile
Re: Improvements to the memory leak warning.
« Reply #1 on: May 16, 2023, 10:28:57 AM »

Thank you for the feedback! I'd tuned it to avoid false alarms in my test cases, but apparently that didn't translate too well to real life use-cases. I've extended the time before a warning by a further 25 seconds, and added a lower-left green message that should show up if the warning was a false alarm, anyway.
Logged

Liral

  • Admiral
  • *****
  • Posts: 726
  • Realistic Combat Mod Author
    • View Profile
Re: Improvements to the memory leak warning.
« Reply #2 on: May 16, 2023, 10:31:57 AM »

Wow, fixed before I even posted my message!

Quote
What he said!  Even in vanilla, Devmode says we get 2 copies of what we figure is the campaign engine when quickloading--and 3 copies when reloading from the main menu.  My mod loves to provoke a Memory Leak pop-up for some reason, too.   :-[  I would very much appreciate any help!

Wyvern

  • Admiral
  • *****
  • Posts: 3878
    • View Profile
Re: Improvements to the memory leak warning.
« Reply #3 on: May 16, 2023, 10:36:13 AM »

I haven't, personally, run into problems with this - so I suspect that someone seeing a plethora of false alarms is probably either running some mod or combination of mods that makes this sort of thing more likely... or perhaps this is an issue with java 8 handling cleanup differently from the game's default java 7?

Now, the memory false alarm I regularly get (and have to go turn off in config because it's just not useful) is the one claiming that I have zero available graphics memory.
Logged
Wyvern is 100% correct about the math.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 25012
    • View Profile
Re: Improvements to the memory leak warning.
« Reply #4 on: May 16, 2023, 10:38:12 AM »

Hmm - are there any opinions on the usefulness of the RAM/VRAM messages?
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3878
    • View Profile
Re: Improvements to the memory leak warning.
« Reply #5 on: May 16, 2023, 10:43:20 AM »

It's probably useful to someone else! Just that that particular number never gets reported right from my particular hardware & software, so I turn off the alarm because it starts sounding off the moment I have any mods installed at all.
Logged
Wyvern is 100% correct about the math.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 25012
    • View Profile
Re: Improvements to the memory leak warning.
« Reply #6 on: May 16, 2023, 10:47:22 AM »

Ah - let me add a check to this that the checker ever picked up a non-zero value for the free VRAM; if it hasn't it's a pretty safe bet that it's not getting any useful information and shouldn't warn.
Logged

Liral

  • Admiral
  • *****
  • Posts: 726
  • Realistic Combat Mod Author
    • View Profile
Re: Improvements to the memory leak warning.
« Reply #7 on: May 16, 2023, 11:31:25 AM »

Ah - let me add a check to this that the checker ever picked up a non-zero value for the free VRAM; if it hasn't it's a pretty safe bet that it's not getting any useful information and shouldn't warn.

Finally!  No more of that.  I was getting it all the time, every time.  Speaking of which, is Starsector meant to expand to the memory allocated to it?  I've heard that it'll just keep loading more into memory until the allocation is full.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 25012
    • View Profile
Re: Improvements to the memory leak warning.
« Reply #8 on: May 16, 2023, 11:53:33 AM »

I don't understand the question, it seems a bit vague.
Logged

Brainwright

  • Admiral
  • *****
  • Posts: 744
    • View Profile
Re: Improvements to the memory leak warning.
« Reply #9 on: May 17, 2023, 06:10:01 AM »

The experience one has when increasing memory allocation to improve mod performance is that the ram/vram warning still keeps popping up.  So, most people will assume the game just consumes all the ram allocated to it, and then starts spitting the message.

Personally, I'm running the linux version on Steam Deck, and it's always displaying the warning no matter what I do, and even when Console Commands reports what seems to be very generous memory remaining.
Logged

SafariJohn

  • Admiral
  • *****
  • Posts: 3098
    • View Profile
Re: Improvements to the memory leak warning.
« Reply #10 on: May 17, 2023, 07:25:13 AM »

or perhaps this is an issue with java 8 handling cleanup differently from the game's default java 7?

No, I saw the X campaign engines messages reduce to one engine using Java 7 many times while testing Roiders. Also saw it not reduce because I was leaking stuff :P It may be that it takes multiple GC passes to clean up certain arrangements of objects. X -> Y -> Z for example may clean X on the first pass, which expires Y, then cleaning Y expires Z.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 25012
    • View Profile
Re: Improvements to the memory leak warning.
« Reply #11 on: May 17, 2023, 07:56:21 AM »

The experience one has when increasing memory allocation to improve mod performance is that the ram/vram warning still keeps popping up.  So, most people will assume the game just consumes all the ram allocated to it, and then starts spitting the message.

Personally, I'm running the linux version on Steam Deck, and it's always displaying the warning no matter what I do, and even when Console Commands reports what seems to be very generous memory remaining.

Just to clarify, one of the the low memory warning is for system memory, not how much is left in the java heap. Maybe that warning should not be shown at all; it seems confusing. One says "low system RAM" and the other one just says "low RAM". Hm.

No, I saw the X campaign engines messages reduce to one engine using Java 7 many times while testing Roiders. Also saw it not reduce because I was leaking stuff :P It may be that it takes multiple GC passes to clean up certain arrangements of objects. X -> Y -> Z for example may clean X on the first pass, which expires Y, then cleaning Y expires Z.

Yep - the game actually gives if a few passes before popping up the memory leak warning, but apparently the amount of waiting was not enough in some cases.
Logged