Jump to content

Memory leak


Recommended Posts

I'm not convinced there's a leak, if it were a memory leak in the stock game the memory used would keep rising until it crashed, and for players with insufficient RAM that can happen (time to upgrade!) and a lot of people are going to say this is exactly what happens but high memory use is not the same as a memory leak.

A leak is when memory set aside for something is never freed for use again.

The terrain system does use a lot of RAM to store the terrain (and the water) you fly over and the objects on it, this is unloaded as you fly around though and when you leave a planet, as long as you have enough memory it's usually able to handle it.

Things get tricky when you have addons however, sorry modders!

Fly around with addon parts, you now have extra stuff in RAM with the game (mostly it's the textures of those parts) and the terrain filling the cache, you get to the point where there's no memory left KSP can use and it crashes.

So what can you do?

You can try reducing the texture size (settings), or convert them to a more compact type (ATM).

You can remove parts you aren't using, that could be a problem when you approach craft that are using those parts though.

Turning off terrain scatters can help too :)

Link to comment
Share on other sites

I'm not convinced there's a leak, if it were a memory leak in the stock game the memory used would keep rising until it crashed, and for players with insufficient RAM that can happen (time to upgrade!) and a lot of people are going to say this is exactly what happens but high memory use is not the same as a memory leak.

There's definitely something going on. I had a pure stock game get close to the memory ceiling - it was rather alarming. Nathan said it can actually hit critical levels, and I have strong faith in his diagnostic skills and such.

Lightly modded games can easily crawl over the limit - my current modded game starts around 2.4 but climbs quickly to ~3.0 and slowly inches towards 3.5 eventually, at which point I restart manually as I know the next launch is going to blow it up...

It could just be some really heinous memory fragmentation, but if it's that bad, it should really be considered a leak.

(I'm not saying it's Squad's fault, it could very well be something within Unity that isn't releasing references or whatever)

Link to comment
Share on other sites

I do not fear the dreaded "memory leak". I've been running KSP .90 32 bit version on my old Dell dinosaur(2Gb ram + 1GB video card) with no crashes and decent framerates. I am actually quite impressed with how good KSP runs considering the scope of the game, simulating space flight through an entire fictional solar system. We've come a long way since the coin op Space Invader and Asteroid machines.

15OldArcadeMachines.jpg

Link to comment
Share on other sites

I'm not convinced there's a leak, if it were a memory leak in the stock game the memory used would keep rising until it crashed

This is normally the case, but thanks to the way Unity loads things, this isn't allowed to happen in a lot of circumstances. Since Unity unloads all assets at scene change, the "leaky" code is unloaded and ignored by the game - this means that in a lot of circumstances the leaky code is unloaded and RAM freed before the game simply crashes from reaching it's memory limit.

As well, you're referring to simply one type of "leak." Memory leaks can also simply be when the software eats up a small amount of memory whenever it does a task, and then never frees it again - this can be demonstrated by simply watching KSP's RAM usage whilst opening tweakable menus in the editor. However, the type you refer to, a constant leak, can also be found in KSP - simply sitting on the runway at the KSC will result in the game continuously increasing it's RAM usage over time, and flying off into space won't free a chunk of that RAM back up (it's rather noticeable when you leave it for around a half hour.) However, returning to the Space Center through the pause menu will free the RAM back up - this strongly suggests that this is a memory leak, and not an intended feature.

Edited by metalmouth7
Link to comment
Share on other sites

This is normally the case, but thanks to the way Unity loads things, this isn't allowed to happen in a lot of circumstances. Since Unity unloads all assets at scene change, the "leaky" code is unloaded and ignored by the game - this means that in a lot of circumstances the leaky data is un-allocated and RAM freed before the game simply crashes from reaching it's memory limit.

As well, you're referring to simply one type of "leak." Memory leaks can also simply be when the software eats up a small amount of memory whenever it does a task, and then never frees it again - this can be demonstrated by simply watching KSP's RAM usage whilst opening tweakable menus in the editor. However, the type you refer to, a constant leak, can also be found in KSP - simply sitting on the runway at the KSC will result in the game continuously increasing it's RAM usage over time, and flying off into space won't free a chunk of that RAM back up (it's rather noticeable when you leave it for around a half hour.) However, returning to the Space Center through the pause menu will free the RAM back up - this strongly suggests that this is a memory leak, and not an intended feature.

Is there any validation to this? tweakables seems to run up the ram usage or something.

SPJnuU0.gif

Link to comment
Share on other sites

Actually Renegrade and metalmouth7 do make a lot of sense, it's easy to miss memory leaks if that memory is reallocated with a scene change, if there is a leak and you are in one scene long enough it will eventually consume all your RAM.

Sarbian has made an in-game memory tool we can use to watch KSP's RAM use and garbage collection that would be very useful for tracking down such leaks, you can find it here.

Of course, the less memory you have free the sooner you'll run out, so anything that maximises free RAM will help to avoid a crash, that's probably why most games suggest you run them without other programs in the background :)

Oh this is off-topic but I was on a site the other day where the moderators would just instaban you for disagreeing with them, luckily we don't do that here, thanks for the info metalmouth7, It's true you can learn something new every day :)

Edited by sal_vager
Link to comment
Share on other sites

I mean someone is SQUAD. Or makers of that damn game engine, forgot it's name.

Sudden slowdown is usually caused by malware or automatic update of some sort. I usually try to setup software to "Only notify" instead of "Suddenly download 1GB patch and ruin my DDO run"

Except it happens after a long while, and I'm pretty sure it's not malware or a download.

Link to comment
Share on other sites

Also don't forget that the state of 0.90.0 isn't indicative of the state of 1.0, memory leaks will be fixed if found, so don't forget to report them on the tracker rather than just writing them off ;)

Edited by sal_vager
Link to comment
Share on other sites

Also don't forget that the state of 0.90.0 isn't indicative of the state of 1.0, memory leaks will be fix if found, so don't forget to report them on the tracker rather than just writing them off ;)

Hmmm...I've come across a few games with memory leaks over the years, I don't think I ever remember one that got completely fixed, just tinkered with to reduce the problem.

Memory leaks are the sort of thing that needs to be identified and squashed during engine development, which doesn't apply to Squad of course as it isn't their engine.

Link to comment
Share on other sites

Huh?

Also, say that your computer suddenly got a major slowdown and stuttering, for absolutely no reason, closing the game doesn't help, only a restart fixes it, what would you call this problem?

Valgrind is a tool to let you hunt memory leaks (and more generally to track memory usage in your programs); it's used by developers to try to eliminate them.

Link to comment
Share on other sites

Is there any validation to this? tweakables seems to run up the ram usage or something.

http://i.imgur.com/SPJnuU0.gif

I am highly alarmed by these two gifs.

A) That's.. a stupendous amount of memory for a tweakable. You could probably screenshot the tweakables, store 'em as bitmaps, and they'd STILL not use that much memory.. what the heck is going on???

B) If you're using commas for the radix point, shouldn't it be spaces or periods for the thousands separator? :S

Link to comment
Share on other sites

Just want to add that I left a somewhat-modded KSP open on a tweakable interface, having done literally nothing else (and it's a tiny sanbox save with nothing going on in it), and KSP only took 15-30 minutes to fill up it's memory and crash:

FAR-Tweakables.jpg

(I opened it just for this screenshot and left it running in the background - basically negligence there ;) )

Logs reported out memory problem, and the process usage was north of 3.8 gigs at that point, having started at 2.5 gigs.

There's definitely something to this tweakable stuff.

Link to comment
Share on other sites

The trouble I'm having is that after some time, KSP becomes stall-ish: every two or three seconds there will be a short break where the game effectively stops and is unresponsive for a moment; works fine in the time between, though, and we're really only taking about moment-long stalls. If they wouldn't repeat so often, I might not notice them. Anyhoo, at that point I know that if I don't restart KSP on my own terms, a restart will soon be forced on me.

I'm under the impression that the condition becomes especially bad when switching between vessels a lot, or when doing the revert-launch cycle over and over again.

Link to comment
Share on other sites

The trouble I'm having is that after some time, KSP becomes stall-ish: every two or three seconds there will be a short break where the game effectively stops and is unresponsive for a moment; works fine in the time between, though, and we're really only taking about moment-long stalls. If they wouldn't repeat so often, I might not notice them. Anyhoo, at that point I know that if I don't restart KSP on my own terms, a restart will soon be forced on me.

I've seen that stuff too, and I saw something in a log once on a game on the verge of a memory crash - the GC was doing emergency cleanups, and it was taking >500ms - that's over a half second, or thirty frames, and is definitely a rather long pause. Way too long for a video game.

Link to comment
Share on other sites

A) That's.. a stupendous amount of memory for a tweakable. You could probably screenshot the tweakables, store 'em as bitmaps, and they'd STILL not use that much memory.. what the heck is going on???

This looks very similar to a leak I accidentally caused in the past through some GUI code (Sane Strategies, that little bit of extra text on the strategies window was doing a few MB/s initially). What happened with me was that every time the element was redrawn, the old version was overwritten but not erased. Now, this doesn't happen with the base Unity Gui code, but that piece of text was written on a custom Squad class. It still leaks like mad when you switch strategies or change commitment , but it only does it when parameters change now(ie. you can force it, but thats not on me any more).

I have a feeling the tweakables suffer from something similar. Instead of drawing the same object, they are updating the object even when no changes are made and the old object is not being discarded properly.

Edited by Crzyrndm
Link to comment
Share on other sites

Not convinced that there are memory leaks? Well, WHATEVER causes my lightly-modded game to freeze up (almost always this happens during scene changes) is really sucking the fun out of the game for me. I hope it gets fixed. I have plenty of memory for KSP to use.

Link to comment
Share on other sites

This looks very similar to a leak I accidentally caused in the past through some GUI code (Sane Strategies, that little bit of extra text on the strategies window was doing a few MB/s initially). What happened with me was that every time the element was redrawn, the old version was overwritten but not erased. Now, this doesn't happen with the base Unity Gui code, but that piece of text was written on a custom Squad class. It still leaks like mad when you switch strategies or change commitment , but it only does it when parameters change now(ie. you can force it, but thats not on me any more).

I have a feeling the tweakables suffer from something similar. Instead of drawing the same object, they are updating the object even when no changes are made and the old object is not being discarded properly.

That DOES sound like it could be related - similar aspects, and similar memory loss rates. Good find!

(it could just be a coincidence, but it's just too suspiciously similar in my mind - got a good lead here I say).

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...