A memory scenario. What's happening?!

Discussion and feedback on Construct 2

Post » Mon Mar 23, 2015 8:25 pm

I actually had some weird issues with memory increases / game crashing after a while while running. I (think/hope) i solved them primarily just by making sure of a few things. Sorry if this is n00b stuff, but I am still teaching myself this shit, so maybe it helps someone else, if not you specifically :D

1) Any of my 'counter' variables either global or instance variables would always stop at a certain amount. So if i had a 'cooldown' or something I'd make sure it only subtracts until it hit 0, then it just stays at 0. Instead of subtracting 1 every second infinitely.

2) Make sure sprites leaving the layout are destroyed or at least 'held' in place instead of infinitely travelling off screen. When i first started there was a lot of out of sight = out of mind... it wasnt until i saw sprites with positions of -1777477x by -28838884y that i realized maybe those were adding to the problem :D

Honestly after a session of cleaning all that stuff up I solved pretty much everyones complaints about crashes / high memory use over time.

I have lots of music in Cosmochoria too... About 30+ tracks & doesnt seem to be a huge issue ATM.
Made Cosmochoria - www.cosmochoria.com
Currently working on Slayaway Camp - www.slayawaycamp.com
B
27
S
8
G
3
Posts: 384
Reputation: 5,020

Post » Tue Mar 24, 2015 1:06 pm

@saiyadjin's suggestion of using Process Explorer is a good idea for a far more detailed breakdown of memory usage. I found it can actually display GPU usage and GPU memory too (one of the only tools I've ever found which can!). But it can also break down RAM usage in to things like "WS Private Bytes" (the private working set) which from what I've read is the most accurate measurement for how much that single process is actually using.

I think Windows' task manager may have changed the measurement it reports at some point. I remember a bug report where someone said Windows task manager indicated it was using something like 600mb of memory, but on my Windows 8.1 it said something like 50mb. I think Windows 8+ reports the private working set size (realistic per-process memory usage) whereas older versions report the full working set size (including memory shared with other processes).

I found an interesting article explaining more about memory measurements here: http://cybernetnews.com/cybernotes-windows-memory-usage-explained/

Here's an interesting analogy:

Lets pretend that there are two kids who are coloring, and both of the kids have 5 of their own crayons. They decide to share some of their crayons so that they have more colors to choose from. When each child is asked how many crayons they used, both of them said they used 7 crayons, because they each shared 2 of their crayons.

The point of that metaphor is that one might assume that there were a total of 14 crayons if they didn’t know that the two kids were sharing, but in reality there were only 10 crayons available.
Scirra Founder
B
387
S
230
G
88
Posts: 24,251
Reputation: 192,464

Post » Sun Apr 05, 2015 8:42 pm

@ashley Sorry for a very late reply. I did some tests to see how much memory my sound effects actually use, and it's close to 400mb of ram when all's loaded in. Of course a lot of this space is sounds that isn't used at any given time. However these sounds represent maybe 1/3 of all the sfx that will be in the final game. I can't accept that 1,2gb will at any given time go to sound effects. I can make systems for making sure the right sounds are loaded in at any given time if I can unload all sounds when I choose. That way I can maybe make sure that the game doesn't use more than maybe 100-300mb of ram for sound at any given time.


Also to address the issue as to what happens when the game use more than 3gb. Well the entire computer freezes until the memory values is sorted out, or it downright crashes (Used Firefox as it's only one process and have a tendency to duplicate memory use after several previews). Finding ways to prevent memory leaks within the game's planned launch of roughly 6 months from now will be crucial.
B
29
S
9
Posts: 356
Reputation: 2,938

Post » Mon Apr 06, 2015 3:49 am

One thing to check is that you don't have any arrays that you grow and never shrink. I once had a memory leak problem and the cause of it all was simply an array that kept getting bigger - since it was global it wasn't destroyed between layouts.

As for 400mb in sound effects, that sounds like a lot! How many SFX files is this, and roughly how long are your files?
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,679

Post » Mon Apr 06, 2015 9:06 am

@sqiddster Can you elaborate on how to monitor arrays? I don't use the array behaviour, but I've always had a feeling that I haven't fully grasped how the assets are loaded in, and that I might have done something wrong. Any documentation on global arrays that's never unloaded? :)

It's a lot of sfx. They're not very long. Like between 0.5-2 seconds on avarage. It's just a lot of quantity, and up to almost 5 variations of every sound.
B
29
S
9
Posts: 356
Reputation: 2,938

Post » Mon Apr 06, 2015 12:45 pm

Yeah, monitoring arrays and memory usage at a more specific level is a huge pain, but I think there's some stuff you can do in Chrome's debugger.

If you don't use arrays at all (I don't know what you mean by array behavior) then that's probably not the problem.

As for SFX, I wish there was something I could tell you! Maybe import them at a lower quality (I have NO idea if that effects runtime memory usage or not), or try to use audio effects instead of subtle variations?
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,679

Post » Wed Apr 08, 2015 1:56 am

you could try making sounds mono instead of stereo, that would cut the filesize in half - although if it's a stereo sound then you won't want to do that.

5 variations seems a bit overkill.. I've use sampled instruments that have less layers!

Sounds like you need to budget out your sound palette and find a place where you can reuse sounds or cut out unnecessary sounds. 400MB for sound is pretty enormous...
B
88
S
29
G
14
Posts: 1,155
Reputation: 15,005

Post » Wed Apr 08, 2015 3:39 am

I think finer controls of memory loading of sfx or art assets is important. In this case, its to reduce the memory footprint, but also in the case of art, it will minimize stutters when a large art asset is required for the first time upon changing layouts. Preload & Unload (especially UNLOAD) should be goto for larger games, rather than asking people to use less sfx or art.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,614

Post » Wed Apr 08, 2015 7:23 am

@jobel Like silverforce is saying. Not having the option to unload assets and sound makes it impossible to make big games. Even if I did compress and reduce the file size somehow, I will still eventually hit a wall. That strategy is only viable if you're making a pea-sized game (that would still use more resources than necessary).
B
29
S
9
Posts: 356
Reputation: 2,938

Post » Wed Apr 08, 2015 6:31 pm

Tinimations wrote: Even if I did compress and reduce the file size somehow, I will still eventually hit a wall.


compression won't help you since the audio is uncompressed in memory. You can however lower the sample rate and/or use mono files wherever it's appropriate. i.e. if you have a gunshot sound that has no stereo image there's NO point in making it a stereo sound. And some less complex sounds will tolerate a lower sample rate without any artifacts etc..

You should use 44.1/16bit anything else is a complete waste unless you are editing the sounds. "Mastered" sounds can be reproduced totally acceptable at 44.1/16 or even less in some cases.

Tinimations wrote: Not having the option to unload assets and sound makes it impossible to make big games.


I disagree. I think limitations are found in any engine or even custom code bases. Every big game ultimately has an "audio budget" of what you can have in memory at a given time. However, I do agree there should be an unload option.. since most programming languages allow you to memset() and free() etc...

But that said, you may want to reconsider the audio design for your game... a 0.5 second sfx saved as a .wav is roughly 100KB (could be more but for the sake of argument let's just say 100). To get to 400MB that means you have approx 4,000 sfx files... I can't imagine there is a game in the world using that many sfx files. Consider if you were to hire someone to create 4,000 sounds for you.. even with variation that's like triple-A type pay... Construct 2 is only $130! I'm just saying: remember the scope.

I use and create sample-based instruments all the time, and that's the territory you are approaching... velocity layers and variations etc... even there, there are tricks to getting your entire virtual instrument into memory. You can use volume, filters and tuning via run-time software to effect the individual sounds making them more "real-like". by any chance is this a music game? (it would make a lot more sense)
B
88
S
29
G
14
Posts: 1,155
Reputation: 15,005

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 1 guest